douhao8456 2012-03-04 03:18
浏览 76
已采纳

$ _POST变量名是变量,如何检索?

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!

  • 写回答

4条回答 默认 最新

  • douxidao3524 2012-03-04 03:20
    关注

    Add some quotes:

    $user_input = $_POST["field$id"];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办