doumixiang2227 2016-09-24 01:46
浏览 60
已采纳

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

  • 写回答

2条回答 默认 最新

  • duanran6441 2016-09-24 02:10
    关注

    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';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测