Computing.Net > Forums > Web Development > Help with Checkboxes and array PHP

Help with Checkboxes and array PHP

Reply to Message Icon

Original Message
Name: sting013
Date: March 10, 2006 at 12:05:26 Pacific
Subject: Help with Checkboxes and array PHP
OS: SUN
CPU/Ram: ?
Model/Manufacturer: ?
Comment:

Hello All, I'm realy new to PHP I have a WebPage that is creation checkbox from a file like this .

<?
$filename = "Jim.txt";
$fp = fopen($filename,"r");
while (!feof($fp))
{
$line = fgets($fp, 4096);
if ($line != null)
{
print "<input type=checkbox name=server[] id=server vaulue=$line>$line";
}
}
fclose($fp);
?>

The problem I'm having is that I can't read the array on the next web page. I know most of the other files I do a $var=$_GET['variable']; but that is not working any help would be great
Thanks


Report Offensive Message For Removal


Response Number 1
Name: Michael J (by mjdamato)
Date: March 10, 2006 at 14:37:51 Pacific
Reply: (edit)

HTML does not "naturally" work with arrays. You are trying to use the name of the checkboxes as an arrat name=server[]. That will not work because once you write it to the page, it is HTML and not PHP.

However, I believe you can have data passed from mutiple fields into a single comma delimited value (at least it works for text boxes and I suspect it will work with checkboxes as well.

Try changing the name of the field to just server without the brackets. You should be able to get the value of all the checkboxes with $_GET['server'] BUT, it will not be in an array. It will come across as a single value in this format "value1,value2,value3, etc. You can then put the values into an arry using the explode command like this: explode(",",$_GET['server']);

However, one last caveat (which you may or may not be aware of). I don't believe that an unchecked checkbox will transfer any value at all. For example, if checkbox 2 had no value you would receive the results: value1,value3 and NOT value1,,value3.

Michael J


Report Offensive Follow Up For Removal

Response Number 2
Name: sting013
Date: March 14, 2006 at 12:25:04 Pacific
Reply: (edit)

Thanks for the reply I will give it a try


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Help with Checkboxes and array PHP

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge