简体   繁体   中英

how to deal with $_POST for a variable which is set as name of a input in a form - PHP

this is where I used $fieldName & $fieldValue in name and value input. these input types are in thousands.I have to store their info so I am writing a code in another PHP file where I can get All values for this input . How to do this?

printf('<input type="text" name="%s" value="%s" /><br/>', $fieldName,$fieldValue );

i tried this which is not working

if(isset($_POST['submit'])){

   $value = $_POST[$fieldName]; 
print_r ($value); }

and I want to get all the value of all inputs as this input is generated in a for loop and its in thousands.I hope you can get my question now

this post value is not getting any value when i submit form

simply write

echo "<pre>";
print_r($_POST);
exit();

and you will get array which will help you.

This is the code that you can use:

foreach ($value as $key => $value1) {
//$value1 has the value of your each input type array, you can use that value in this loop in the way you wish to.
}

I hope this helps you.

Try using an array input field:

printf('<input type="text" name="name[%s]" value="%s" /><br/>', $fieldName,$fieldValue );

Then get the all posted inputs for "name" as:

$all_values = isset($_POST['name']) ? $_POST['name'] : Array();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM