PHP 引发 SQL 语法错误

标签 php mysql

我是 PHP 和 SQL 的新手,但我正在创建一个登录系统。我遇到的问题是:

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 'Surname typed in')' at line 5

所以我查看了代码,我相信它指的是:

    mysql_query("INSERT INTO users (email, password, hash, forename, surname) VALUES(
        '". mysql_escape_string($email) ."',
        '". mysql_escape_string($password) ."',
        '". mysql_escape_string($hash) ."',
        '". mysql_escape_string($forename) .",
        '". mysql_escape_string($surname) ."') ") or die(mysql_error());

看了看,没看出语法错误。有人发现了吗?

最佳答案

在这一行:

'". mysql_escape_string($forename) .",
                                  // ^--- no closing single quote here.

您忘记了结束引号。

关于PHP 引发 SQL 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15047048/

相关文章:

php - 变量中的 If 逻辑(谓词表达式)

mysql - 表大小会影响 INSERT 性能吗?

php - 使用 PHP 动态验证 HTML 表单

php - 将 XML 从 php 返回到 C++ 应用程序

php - 如何在 vb.net 中合并字符串日期和时间并转换为带有军事格式的日期和时间?

php - 难以获取html表单和database.php以通信/显示我从MySQL Sever中搜索的表单数据

php - 高效评论系统分页查询

php - 连接和使用 mysqli_insert_id() 的返回类型有什么问题?

php - php 响应错误

php - Mysql - 在重复键上插入不同的值