Reputation: 571
I am having some trouble with the last little thing in my project.
I can modify a record with a form on the index page, but when I have the update button call the modifyRecord page, I can't figure out how to obtain the variable for the 'reg' (reg ID from drawer2). I have it as the value (see code) but when I try to use this or store it in a variable, I get an undefined index error. Not sure what I need to be doing??
FROM INDEX.PHP: (this happens in every loop that shows a record)
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>");
}
I was playing around with trying to store the value in a variable: (from modifyRecord.php)
if(isset($_POST['mod']))
{
echo 'POST Mod is set';
$regId = $_REQUEST['reg'];
}
But the echo never displays...
Not sure what is going wrong. Thank You...
Upvotes: 1
Views: 136
Reputation: 11485
Try this:
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'];
}
Upvotes: 2
Reputation: 887
You forgot the apostrophe on the values.
Try this code:
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>");
Upvotes: 3