Forum Moderators: coopster

Message Too Old, No Replies

$_POST Error

         

wfernley

7:25 pm on Apr 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi everyone :)

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

jatar_k

7:31 pm on Apr 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I am guessing that in your form you wnat this

<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"?

wfernley

7:39 pm on Apr 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes. The form itself works fine. It's just when I try to grab the $_POST variables from the checkboxes it says :

Undefined index: $manufacturer["manf_id"]

or

whatever variable I have in the $_POST[]

Wes

wfernley

7:47 pm on Apr 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here this code might help:

$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? :)

Netizen

8:03 pm on Apr 21, 2004 (gmt 0)

10+ Year Member



Try

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.

wfernley

8:05 pm on Apr 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey great! That works :)

LoL I hate being new at this. The smallest little things cause the biggest headaches.

Thanks for your help once again :)

Wes

MrCrowley

8:09 pm on Apr 21, 2004 (gmt 0)

10+ Year Member



print $_POST['$manufacturer["manf_id"]']; will really get $_POST['$manufacturer["manf_id"]']; . On the other hand, $_POST[$manufacturer["manf_id"]]; will get $_POST['TEST'];. As Netizen pointed out, the single quotes. Remember that vars are not interpreted inside single quotes. And when you access arrays inside double quotes, you have to put the names inside brackets : "{$_POST['$manufacturer['manf_id']]}";

wfernley

8:16 pm on Apr 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ahhh ok.

I always had problems with knowing what quotes to use.

Wes

bgrobe

1:12 am on Apr 25, 2004 (gmt 0)

10+ Year Member



Define another variable:

$temp=$manufacturer["manf_name"]
$_POST[$temp];

That is how it is done. I have tried doing it your way before when I was starting out, and I found out that doing it like that works perfectly...