MySQL UPDATE 查询不起作用

发布于 2024-11-07 02:58:13 字数 2417 浏览 0 评论 0原文

这个脚本有什么问题?我无法弄清楚这个问题!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不必了 2024-11-14 02:58:13

UPDATE 命令中,去掉括号。就是这样。

另外,请注意SQL 注入

更新

最终代码应如下所示:

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_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");
}

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:

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_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");
}
浅笑轻吟梦一曲 2024-11-14 02:58:13

这里的问题是你调用了错误的函数。 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 be mysql_query.

You also don't need the parenthesis after SET.

Regarding sql injection, I suggest you escape all $_POST variables with mysql_real_escape_string.

情泪▽动烟 2024-11-14 02:58:13

根据 PHP 文档,已弃用的函数 mysql_db_query( ) 至少需要两个参数。第一个是数据库名称,第二个是 SQL 查询。您仅指定了 SQL 查询。

resource mysql_db_query ( string $database , string $query [, resource $link_identifier ] )

因此,在您的情况下:

mysql_db_query('yourdatabasename', "UPDATE accounts set....");

现在更常见的是使用 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.

resource mysql_db_query ( string $database , string $query [, resource $link_identifier ] )

So in your case:

mysql_db_query('yourdatabasename', "UPDATE accounts set....");

More common these days is to use mysql_query(), which will make use of the database previously selected with mysql_select_db().

愚人国度 2024-11-14 02:58:13

检查mysql连接是否建立。
有时这也可能是一个问题,

mysql_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") 

这是更新查询的语法,使用 mysql_query 而不是 mysql_db_query

Check whether mysql connection is established.
Some times that might also be a problem

mysql_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") 

this is the syntax to update the query, use mysql_query instead of mysql_db_query

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文