Forum Moderators: coopster
I was curious what I'm doing wrong here.
I have a form with a checkbox which is grabbing the name from a MySQL DB.
<input type="checkbox" name="<?php print $manufacturer["manf_name"];?>" value="yes">
Let I am trying to use the $_POST['$manufacturer["manf_name"]']
Will the variable $manufacturer["manf_name"] show up inside the $_POST? For some reason it is not showing up in my code. I was curious what I need to add to get this to work. :S
The variable $manufacturer["manf_name"] = "TEST"
and I want the $_POST['$manufacturer["manf_name"]'] to show up as $_POST['TEST']
Thanks for your help.
Wes
<input type="checkbox" name="<?php print $manufacturer["manf_name"];?>" value="yes">
to actually show
<input type="checkbox" name="TEST" value="yes">
so you can access it in the script the form is posted to as
$_POST['TEST']
when you view source on the form page what exactly do you see for this checkbox element?
Where are you testing for the existence of the var in the $_POST array? I assume in the script which the form posts to with a small line like
echo $_POST['TEST'];
is the form set to action="post"?
$manf_query = mysql_query("SELECT * FROM wheretobuy");
while ($manufacturer = mysql_fetch_array($manf_query)) {
?>
<tr>
<td width="25"><input type="checkbox" name="<?php print $manufacturer["manf_id"];?>" value="yes"></td>
<td width="125"><?php print $manufacturer["manf_name"];?></td>
</tr>
<?php
}
?>
That displays fine in the form.
This is the other part:
$manf_query = mysql_query("SELECT * FROM wheretobuy");
while ($manufacturer = mysql_fetch_array($manf_query)) {
print $_POST['$manufacturer["manf_id"]'];
}
Does this help at all? :)
print $_POST[$manufacturer["manf_id"]];
instead of
print $_POST['$manufacturer["manf_id"]'];
By putting single quotes around the $manufacturer["manf_id"] you were using it in a string context i.e. you were asking for the string $manufacturer["manf_id"] not the value in that variable.
Also, you might get warnings if the checkbox hasn't been selected - it sounds like you have E_NOTICE set.