我想更新我的数据库和这段代码,以便在另一个表上正常工作,但这里我有一个错误,我看到了这条消息:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE
id
='588'' at line 4
<?php
$sel_item = "SELECT * FROM `employees` where id=".$_GET['emp_id'];
$done_item = mysql_query($sel_item);
$get_item = mysql_fetch_array($done_item);
if(isset($_POST['edit']) ){
$upd= "UPDATE `employees` SET
`emp_no`='".$_POST['name']."',
WHERE `id`='".$_POST['id']."";
$do_upd = mysql_query($upd) or die(mysql_error());
}
?>
<form action="" method="post" enctype="multipart/form-data">
<table class="append-row" width="100%" border="0" bgcolor="#006699" height="60px" align="left"
style="padding:0 30px;">
<tr>
<td><input type="text" name="name" id="name" placeholder="name" value="<? php echo $get_item['emp_no'];?>"></td>
<input type="hidden" name="id" id="id" value="<?php echo $get_item['id'];?>" >
<td><input type="submit" name="edit" id="edit" value="edite"></td>
</tr>
</table>
</form>
最佳答案
您在 UPDATE 语句中的 $_POST['id'] 之后缺少结束单引号,并且在 WHERE 条件之前还有一个不需要的逗号。
尝试:
$upd= "UPDATE `employees` SET `emp_no`='".$_POST['name']."' WHERE `id`='".$_POST['id']."'";
关于php - 用php更新mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16819754/