Posts: 164
Name: James
Location: marbella & surrey
|
I'm trying to return the name attribute of a radio button from the $_POST data.
i'm never great at explaining my problem on paper so my -simplified- code below should make it clear, to smarter people than me, where i went wrong.
this is my html:
Code:
<input type="radio" name="rad_1" id="show_1 value="1">show
<input type="radio" name="rad_1" id="hide_1 value="0">hide
<input type="radio" name="rad_2" id="show_2 value="1">show
<input type="radio" name="rad_2" id="hide_2 value="0">hide
....etc.... this goes on an unknown number of times...
and this is my php:
Code:
foreach($_POST as $post_up) {
if ($post_up['value']) $sql .= "INSERT INTO table VALUES ('" . $post_up['name'] . "')";
}
if i print_r($_POST) i get the expected Array ([rad_1] => 0, [rad_2] =>1 .....)
it's the bit inside the [square brackets] i need to return to use in my insert
statement.
if anyone has ANY input on this i'd be very grateful as i've spent hours googling and reading the php.net docs with little luck.
many thanks
purk
the reason for the iteration is at runtime i don't know exactly how many radio buttons there will be so i want to cycle through the whole of the $_POST.
my actual code is much bulkier so i stripped the unimportant stuff so if there are any glaringly obvious mistakes it's likely to be just in this posting as my code executes without errors (just not as i would like).
__________________
Please login or register to view this content. Registration is FREE - private villas direct from the owners - travel links always needed.
|