MySQL UPDATE 查询不起作用
这个脚本有什么问题?我无法弄清楚这个问题!
function editAccount() {
$id = $_POST['id'];
$rep = $_POST['rep'];
$lastchange = date('mdY');
$account = $_POST['account'];
$areacode = $_POST['areacode'];
$number = $_POST['number'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$fax = $_POST['fax'];
$descmaker1 = $_POST['descmaker1'];
$descmaker2 = $_POST['descmaker2'];
$title = $_POST['title'];
$email = $_POST['email'];
$cvendor = $_POST['cvendor'];
$cequipment = $_POST['cequipment'];
$leaseexp1 = $_POST['leaseexp1'];
$leaseexp2 = $_POST['leaseexp2'];
$leaseexp3 = $_POST['leaseexp3'];
$leaseexp4 = $_POST['leaseexp4'];
$leaseexp5 = $_POST['leaseexp5'];
$leaseexp6 = $_POST['leaseexp6'];
$volume = $_POST['volume'];
$notes = $_POST['notes'];
mysql_db_query("UPDATE accounts
SET (lastchange = '$lastchange',
account = '$account',
areacode = '$areacode',
number = '$number',
address1 = '$address1',
address2 = '$address2',
city = '$city',
state = '$state',
zip = '$zip',
fax = '$fax',
descmaker1 = '$descmaker1',
descmaker2 = '$descmaker2',
title = '$title',
email = '$email',
cvendor = '$cvendor',
cequipment = '$cequipment',
leaseexp1 = '$leaseexp1',
leaseexp2 = '$leaseexp2',
leaseexp3 = '$leaseexp3',
leaseexp4 = '$leaseexp4',
leaseexp5 = '$leaseexp5',
leaseexp6 = '$leaseexp6',
volume = '$volume',
notes = '$notes')
WHERE id = $id");
}
错误:
警告:第 83 行 /home/content/53/7311353/html/cca/accounts/include/processAct.php 中 mysql_db_query() 的参数计数错误
为:WHERE id=$id");< /代码>
What is wrong with this script? I cannot figure out the issue!
function editAccount() {
$id = $_POST['id'];
$rep = $_POST['rep'];
$lastchange = date('mdY');
$account = $_POST['account'];
$areacode = $_POST['areacode'];
$number = $_POST['number'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$fax = $_POST['fax'];
$descmaker1 = $_POST['descmaker1'];
$descmaker2 = $_POST['descmaker2'];
$title = $_POST['title'];
$email = $_POST['email'];
$cvendor = $_POST['cvendor'];
$cequipment = $_POST['cequipment'];
$leaseexp1 = $_POST['leaseexp1'];
$leaseexp2 = $_POST['leaseexp2'];
$leaseexp3 = $_POST['leaseexp3'];
$leaseexp4 = $_POST['leaseexp4'];
$leaseexp5 = $_POST['leaseexp5'];
$leaseexp6 = $_POST['leaseexp6'];
$volume = $_POST['volume'];
$notes = $_POST['notes'];
mysql_db_query("UPDATE accounts
SET (lastchange = '$lastchange',
account = '$account',
areacode = '$areacode',
number = '$number',
address1 = '$address1',
address2 = '$address2',
city = '$city',
state = '$state',
zip = '$zip',
fax = '$fax',
descmaker1 = '$descmaker1',
descmaker2 = '$descmaker2',
title = '$title',
email = '$email',
cvendor = '$cvendor',
cequipment = '$cequipment',
leaseexp1 = '$leaseexp1',
leaseexp2 = '$leaseexp2',
leaseexp3 = '$leaseexp3',
leaseexp4 = '$leaseexp4',
leaseexp5 = '$leaseexp5',
leaseexp6 = '$leaseexp6',
volume = '$volume',
notes = '$notes')
WHERE id = $id");
}
Error:
Warning: Wrong parameter count for mysql_db_query() in /home/content/53/7311353/html/cca/accounts/include/processAct.php on line 83
Line is: WHERE id=$id");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在
UPDATE
命令中,去掉括号。就是这样。另外,请注意SQL 注入。
更新
最终代码应如下所示:
In the
UPDATE
command, lose the parenthesis. That's it.Also, please, beware of SQL Injection.
Update
Here's how the final code should look like:
这里的问题是你调用了错误的函数。
mysql_db_query
应为mysql_query
。您也不需要
SET
之后的括号。关于sql注入,我建议你使用
mysql_real_escape_string
<来转义所有$_POST
变量/a>.The problem here, is you're calling the wrong function.
mysql_db_query
should bemysql_query
.You also don't need the parenthesis after
SET
.Regarding sql injection, I suggest you escape all
$_POST
variables withmysql_real_escape_string
.根据 PHP 文档,已弃用的函数
mysql_db_query( )
至少需要两个参数。第一个是数据库名称,第二个是 SQL 查询。您仅指定了 SQL 查询。因此,在您的情况下:
现在更常见的是使用
mysql_query()
,它将利用之前通过mysql_select_db()
选择的数据库。According to PHP docs, the deprecated function
mysql_db_query()
takes at least two parameters. First, is the database name and second is the SQL query. You've only specified the SQL query.So in your case:
More common these days is to use
mysql_query()
, which will make use of the database previously selected withmysql_select_db()
.检查mysql连接是否建立。
有时这也可能是一个问题,
这是更新查询的语法,使用 mysql_query 而不是 mysql_db_query
Check whether mysql connection is established.
Some times that might also be a problem
this is the syntax to update the query, use mysql_query instead of mysql_db_query