用php更新mysql数据库 [英] Update mysql database with php
本文介绍了用php更新mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更新我的数据库,这段代码在另一个表上运行良好,但在这里我有一个错误,我看到了这条消息:
I want to update my database and this code in working good on another table but here i have an error and i see this message:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解要在第 4 行的WHERE id
='588'' 附近使用的正确语法
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 条件.
You are missing the closing single quote after the $_POST['id'] in the UPDATE statement and you also have a comma you don't need before the WHERE condition.
试试:
$upd= "UPDATE `employees` SET `emp_no`='".$_POST['name']."' WHERE `id`='".$_POST['id']."'";
这篇关于用php更新mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文