Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$_POST variable name is variable, how to retrieve?

Tags:

php

Users of my website can generate a custom form. All the fields are saved in a database with a unique ID. When someone visits the form, the fields 'name' attribute is field*ID*, for example

<p>Your favorite band? <input type="text" name="field28"></p>
<p>Your Favorite color? <input type="text" name="field30"></p>

After submitting the form, I use php to validate the form, but I don't know retrieve the value of $_POST[field28] (or whatever number the field has).

<?
while($field = $query_formfields->fetch(PDO::FETCH_ASSOC))
 {
 $id = $field[id];

 //this doesn't work!!
 $user_input = $_POST[field$id];

 //validation comes here
 }
?>

If anybody can help me out, it's really appreciated!

like image 712
dirk Avatar asked Nov 29 '22 03:11

dirk


1 Answers

Add some quotes:

$user_input = $_POST["field$id"];
like image 129
Amber Avatar answered Dec 18 '22 23:12

Amber