使用VAR DUMP POST以及如何将值转换为变量

使用VAR DUMP POST以及如何将值转换为变量

问题描述:

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

我在帖子上进行var转储时有一个表单我得到一个这样的数组 p> \ n

  array(1){[1338099133] =&gt;  string(9)“精装”} 
  code>  pre> 
 
 

但是当我尝试使用单选按钮的名称设置变量时,它给出了一个未定义变量的错误, 尽管无线电输入的名称与post值匹配,并且var dump在post ...中显示了一些值... 如何删除post中的值到变量请帮助 这是我的代码,显示收音机 in put p>

 &lt; input type =“radio”name ='。$ arr [$ row] ['isbn']。'  value =“精装”&gt;精装:
  code>  pre> 
 
 

这里是我的帖子变量 p>

  var_dump($ _ POST  ); 
 
 $ value = $ _POST [$ row] ['isbn']; 
  code>  pre> 
 
 

am我可能是指错了...? div>

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];