Error: You have an error in your SQL syntax; check the manual that corresponds t

论坛首页 论坛 寻求帮助 Error: You have an error in your SQL syntax; check the manual that corresponds t

正在查看 1 条回复
  • 作者
    帖子
    • #21443
      咸寒少
      参与者
        @smallsaltedfish
        楼主
        呆憨Blog
        blog.daihan.top

        Error: 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 ‘@qq.com,Sukanu,test6666,,0,e0138398ab2acec0073e5ba8100a62ad)’ at line 1

        关于这个错误 好像说我的这一句

        $reg_sql = "INSERT INTO user (user_mail, user_name, user_passwd,user_invite_code,user_mail_status,user_token) VALUES (" . $post['mail'] . "," . $post['name'] . "," . $post['passwd'] . "," . $post['invite_code'] . ",0,$md5)";

        存在问题 但是我不明白这句哪里出错

        另外 像这样有多个参数的sql语句 如果不用拼接字符串的方式,还有哪些方式来避免sql注入?

      • #21444
        孙锡源
        管理员
          @ibadboy
          坏蛋的博客
          ibadboy.net

          SQL 语句中的值应该用单引号包裹。而且你这么写会被 SQL 注入的。

          在 WordPress 中你可以使用 $wpdb 的 prepare 方法来格式化 SQL,具体用法百度搜一下,有很多教程。

          • #21445
            咸寒少
            参与者
              @smallsaltedfish
              楼主
              呆憨Blog
              blog.daihan.top

              这个并不是wordpress 如何避免注入

              • #21446
                孙锡源
                管理员
                  @ibadboy
                  坏蛋的博客
                  ibadboy.net

                  所以你具体使用的是什么?

                  如果是原生 PHP 纯手敲的话可以使用 MySQLi 的 prepare 方法。

                  如果是使用了框架的话,几乎可以说 100% 有自带的格式化方法。百度搜一下应该很容易搜到。

          正在查看 1 条回复
          • 哎呀,回复话题必需登录。