I have a form when I do var dump on post am getting an array like this
array(1) { [1338099133]=> string(9) "hardcover" }
However when I try to set a variable with the name of the radio button it is giving me an error of undefined variable, despite the fact that the name of the radio input matches the post value and that var dump is showing some values in post... How do I remove those values in post to a variable please help Here is my code that shows the radio in put
<input type="radio" name='.$arr[$row]['isbn'].' value="hardcover" >Hardcover:
and here is my post variable
var_dump($_POST);
$value = $_POST[$row]['isbn'];
am I maybe refering to it wrong...?
It appears the undefined variable is $row
.
I'm assuming that you are looping through $arr
, grabbing the row and outputting each line for your input element. When you go to grab the item from the $_POST
array, $row
isn't set and that's throwing the error.
The generated html would look like:
<input type="radio" name='1338099133' value="hardcover" >Hardcover:
which matches the key & value in your $_POST
array on submit.
To fix this, you'll need to come up with a known name instead of a dynamic one. Something like the following should work:
<input type="radio" name="isbn['.$arr[$row]['isbn'].']" value="hardcover" >Hardcover:
Which then allows you to loop through all of your inputs on submission:
foreach ( $_POST['isbn'] as $isbn => $response ) {
// $isbn = 1338099133;
// $response = 'hardcover';
}
the array key is "1338099133" its value is "hardcover"
if $row
in your example is "1338099133" then to set $value
to "hardcover" its.
$value = $_POST[$row];