Forum Moderators: coopster
i made the checkboxes an array.
the problem is, when i try to print the array, what prints is the name of the array itself and not the content of the array.
here's the code
$check_entries=array();
$check_entries=$_POST["check_entries"];
$check_count = count($check_entries);
print($check_count);
for($a=0; $a<$check_count; $a++)
{
print($check_entries[$a]);
}
output:
check_entriescheck_entries
output should be:
cat dog
foreach($check_entries as $name => $value)
{
echo "Name: $name Value: $value<br>";
}
Then you will know what is the field and it's value. Maybe as dreamcatcher suggested you have sth wrong with your html?
Best regards
Michal Cibor
PS. The code you wrote should work
anyway, this is the whole code
<?php
require_once("db.lib.php");
$link=db_open();
$sql="select * from tblentries where fldmarker!='deleted' ORDER BY fldeid";
$result=mysql_query($sql,$link);
while($row = mysql_fetch_array($result))
{
print('<tr>');
print('<td height="20"> </td>');
print('<td colspan="3" align="center" valign="middle">'.$row["fldename"].'</td>');
rint('<td> </td>');
//HERE IS MY CHECKBOX,ITS ACTUALLY IN A LOOP SO I CAN'T REALLY NAME IT ALL COZ THE NAME WOULD ACTUALLY DEPEND ON THE LOOP
print('<td align="center" valign="middle"><input type="checkbox" name="check_entries[]" value="check_entries[]"></td>');
print('<td> </td>');
print('</tr>');
}
?>
AND THE FORM WHO RECEIVES IT HAS THIS
$check_entries=array();
$check_entries=$_POST["check_entries"];
$check_count = count($check_entries);
print($check_count);
print($check_entries[0]);
print($check_entries[1]);
for($a=0; $a<$check_count; $a++)
{
//if (isset($_POST['check_entries[$a]' . $i]))
//{
print($check_entries[$a]);
//}
}
IT PRINTS CHECK_ENTRIES OVER AND OVER AGAIN
print('<td align="center" valign="middle"><input type="checkbox" name="check_entries[]" value="check_entries[]"></td>');
print('<td align="center" valign="middle"><input type="checkbox" name="check_entries[]" value="'.$row["fldename"].'"></td>');
Best regards
Michal Cibor
value="' . $row["fldename"] . '"></td>')
that is: after value you must have double quote: ", and then single quote: '.
It is because if you write:
$v = "Kate";
echo "Welcome $v";// Welcome Kate - the parser will see that it's the variable. However
echo 'Welcome $v';// Welcome $v - the parser thinks this is only text, no variables in it!
So to correct the second:
echo 'Welcome '.$v;// Welcome Kate
Hope this cleares the things up for you!
Best regards
Michal Cibor