我有一张桌子,因为我有4 text fields
。所以当我在所有文本字段框中输入值时。当我按Update button
时。输入的值未显示在我的数据库中。这是我的代码:
以下代码适用于文本框:
<td class="answer">
<input type="text" name="Answer1" value='<?php echo $obj["Answer1"]; ?>' /></td>
<td class="answer">
<input type="text" name="Answer2" value='<?php echo $obj["Answer2"]; ?>' /></td>
<td class="answer">
<input type="text" name="Answer3" value='<?php echo $obj["Answer3"]; ?>' /></td>
<td class="answer">
<input type="text" name="Answer4" value='<?php echo $obj["Answer4"]; ?>' /></td>
我的更新按钮代码:
if(isset($_POST["update_question"]))
{
$Question_Id=$_POST["update_question"];
$Question_Name=$_POST["Question_Name"];
$Answer1=$_POST["Answer1"];
$Answer2=$_POST["Answer2"];
$Answer3=$_POST["Answer3"];
$Answer3=$_POST["Answer4"];
$update_question="UPDATE `tblquestions` SET `Question_Name`='".$Question_Name."', `Answer1`='".$Answer1."', `Answer2`='".$Answer2."', `Answer3`='".$Answer3."', `Answer4`='".$Answer4."',`ModifiedDate`=NOW() WHERE `Question_Id`='".$Question_Id."'";
$update_result=mysqli_query($con,$update_question);
if($update_result)
{
echo "<script> window.location.href='question.php?msg=sucmsg';</script>";
}
else
{
echo "<script> window.location.href='question.php?msg=errmsg';</script>";
}
}
<button type="submit" name="update_question" class="button" value="<?php echo $obj["update_question"]; ?>">Update</button>
当我输入所有字段值时,当我在数据库中没有按任何更新时。提前谢谢!
答案 0 :(得分:1)
您错过了以下表格中的这些字段:
<input type="hidden" name="Question_Id" value='<?php echo $obj["Question_Id"]; ?>' /></td>
//just to set any value inside to update_question:
<input type="hidden" name="update_question" value='1' /></td>
按这样更改按钮:
<input type="submit" class="button">Update</input>
然后在剧本中:
if(isset($_POST["update_question"]))
{
$Question_Id=$_POST["Question_Id"];
...
}
答案 1 :(得分:-1)
表格中没有update_question
列,这是提交按钮的名称。列名称为Question_Id
,因此您应使用$obj['Question_Id']
代替$obj['update_question']
。