PHP/SQL注册表单不起作用


PHP/SQL sign-up form is not working

我正试图为我的网站创建一个注册表单,但我的sql查询返回错误

$sql failed: 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 ''username','password','forename','surname','title') VALUES ('f','f','f','f','f')' at line 1

这是我在signupaction.php中的代码:

<?php 
include('connect.php');
$username=$_POST["forename"];
$password=$_POST["surname"];
$forename=$_POST["username"];
$surname=$_POST["password"];
$title=$_POST["title"];
$sql = "INSERT INTO users ('username','password','forename','surname','title') VALUES ('$username','$password','$forename','$surname','$title')";
$result = mysql_query($sql, $link)  or exit('$sql failed: '.mysql_error());
echo($result);
?>

我不知道为什么这不起作用,任何建议都将不胜感激!谢谢

您不需要用单引号包装字段的名称。你可以按原样离开,也可以使用反勾号。使用引号会让mysql认为您在处理字符串。

试试这样的东西-

$sql = "INSERT INTO users (username,password,forename,surname,title) VALUES  
        ('$username','$password','$forename','$surname','$title')";

不要引用SQL语句中第一组parens中的字段名。

然后切换到mysqli!让你的生活更轻松。