我正在尝试使用PHP表单更新数据库数据的代码。我的代码似乎无法正常工作,因为我得到的只是"无法更新数据。"当我检查数据库中的表时,没有完成更新。有人可以告诉我我的代码有什么问题
的index.php
<body>
<form method="post" action="update.php">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">ID</td>
<td><input name="emp_id" type="text" id="emp_id"></td>
</tr>
<tr>
<td width="100">Date of Birth</td>
<td><input name="birth" type="date" id="birth"></td>
</tr>
<tr>
<td width="100">Educational Background</td>
<td><input name="edu" type="text" id="edu"></td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="update" type="submit" id="update" value="Update">
</td>
</tr>
</table>
</form>
update.php
<?php
$conn = mysqli_connect("localhost", "root", "", "test");
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$emp_id = $_POST['emp_id'];
$birth = $_POST['birth'];
$edu = $_POST['edu'];
$sql = "UPDATE vtiger_leadscf
SET birth = '$birth',
edu = '$edu'
WHERE emp_id = '$emp_id'" ;
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
?>
答案 0 :(得分:0)
替换您的查询
$sql = "UPDATE vtiger_leadscf
SET birth = '".$birth."',
edu = '".$edu."'
WHERE emp_id = ".$emp_id ;