i need to reproduce with the code below something like:
myformdata[languages1]
myformdata[languages2]
myformdata[languages3]
But with this code only reproduce myformdata[languages
<?php
$sql=mysql_query("select id_spoken_languages, language, path from spoken_languages");
$i=0;
while($row=mysql_fetch_array($sql)) {
$id=$row['id_spoken_languages'];
$data=$row['language'];
$flag=$row['path'];
echo nl2br ("<input type='checkbox' name='myformdata[languages'.$i++.']' value='$id' class='semLargura'>$data <img style='float:right; margin-top:5px; border:1px solid grey;' src='$flag'></img> \n");
}
?>
i already tried remove the increment and only access with $form_data_array["languages"][1] but in this case i get:
Notice: Uninitialized string offset: 1 in C:\Users\fel\VertrigoServ\www\login\validation2.php on line 9
but if i use `$form_data_array[“languages”][0], no error is showed, seems like all checkbox have the
index 0.
what is the best way to solve this problem?
It looks like your output string may be incorrect. Try this one:
I replaced the two instance of single quotes before and after the increment output with double quotes.
Also note, there is no need to increment in PHP. All you need to add is two empty brackets
[]and PHP will take care of the incrementing itself. So if you’d like to access the input with$_POST["languages"][1]you can do so by generating the following:name='languages[]'.