我在项目的最后一件小事上遇到了一些麻烦。
我可以在索引页面上修改带有表单的记录,但是当我有更新按钮调用modifyRecord页面时,我无法弄清楚如何获取'reg'的变量(来自drawer2的reg ID) 。我将它作为值(参见代码),但是当我尝试使用它或将其存储在变量中时,我得到一个未定义的索引错误。不确定我需要做什么?
FROM INDEX.PHP :(这发生在每个显示记录的循环中)
foreach($resultdet as $res2){
printf($format, $res2['Id'], $res2['Value1'], $res2['Value2'], $res2['reg']);
echo("<form method='Post' action='modifyRecord.php'><input type ='hidden' value =".$res2['Id'].
" name = 'Id'/><input type ='hidden' value =".$res2['reg'].
" name = 'reg'/><input type = 'submit' value = 'modify' name = 'mod'/>
</form>");
}
我正在尝试将值存储在变量中:(来自modifyRecord.php)
if(isset($_POST['mod']))
{
echo 'POST Mod is set';
$regId = $_REQUEST['reg'];
}
但回声从未显示......
不确定出了什么问题。谢谢......
答案 0 :(得分:3)
你忘记了价值观的撇号。
试试这段代码:
echo("<form method='Post' action='modifyRecord.php'><input type='hidden' value='" .
$res2['Id'] .
"' name='Id'/><input type ='hidden' value='".$res2['reg'].
"' name='reg'/><input type='submit' value='modify' name='mod'/>
</form>");
答案 1 :(得分:2)
试试这个:
foreach ($resultdet as $res2)
{
printf($format, $res2['Id'], $res2['Value1'], $res2['Value2'], $res2['reg']);
$data "
<form method='Post' action='modifyRecord.php'>
<input type='hidden' value=\"{$res2['Id']}\" name='Id' />
<input type='hidden' value=\"{$res2['reg']}\" name='reg' />
<input type='submit' value='modify' name='mod' />
</form>";
echo $data;
}
if (isset($_POST['mod']))
{
echo 'POST Mod is set';
$regId = $_REQUEST['reg'];
}