php mysql update的小问题

[复制链接]
查看11 | 回复1 | 2011-4-15 10:55:37 | 显示全部楼层 |阅读模式
请教下各位大虾,我使用的php mysql,我更新数据时总也更新不了,请大虾审阅下代码,如下:

定义:
functionupdate_all($id,$tan,$aa,$ab,$ac) {
$conn = dlink();
$conn-query(\"set names utf8\");
$result = $conn-query(\"select * from my_db where id=\'\".$id.\"\'\");
if (!$result) {

throw new Exception(\'错误,请重试!\');
}
$query = \"update question_db set tan=\".$tan.\",aa=\".$aa.\",ab=\".$ab.\",ac=\".$ac.\" where id=\".$id;
$result = $conn-query($query);
if (!$result) {
throw new Exception(\'Error.could not update!\');
}
return true;
}
调用更新语句:update_all($id,$tan,$aa,$ab,$ac);

$query = \"update question_db set tan=\".$tan.\",aa=\".$aa.\",ab=\".$ab.\",ac=\".$ac.\" where id=\".$id; 这句之前我输出id、tan、aa、ab、ac都有内容的,但就是更新不成功,请各位大虾不吝赐教哦,感激不尽!!!!
回复

使用道具 举报

千问 | 2011-4-15 10:55:37 | 显示全部楼层
<pre id=\"best-answer-content\" class=\"reply-text mb10\">检查tan aa ac这些字段的数据类型,如果是字符或字符串,更新语句就不对了,应该加单引号:
query = \"update question_db set tan=\'\".$tan.\"\',aa=\'\".$aa.\"\',ab=\'\".$ab.\"\',ac=\'\".$ac.\"\' where id=\".$id;

















<h4 class=\"ask\">追问





<pre class=\"replyask-text\" id=\"content-4517861\">如果里面这些字段类型既有字符串类又有日期类等,请问该怎么修改呢?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行