请注意语法错误

-1 php mysql forms

我收到以下错误:


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 ''login' ('id', 'uname', email', 'pass') VALUES (NULL, 'X', 'X' at line 1
Run Code Online (Sandbox Code Playgroud)

代码如下:


<?php

    require('config.php');
    if(isset($_POST['submit'])){

        //Perform the verification
        $email1 = $_POST['email1'];
        $email2 = $_POST['email2'];
        $pass1 = $_POST['pass1'];
        $pass2 = $_POST['pass2'];

        if($email1 == $email2){
            if($pass1 == $pass2){
                //All good. Carry on.

                $uname = mysql_escape_string($_POST['uname']);
                $email1 = mysql_escape_string($email1);
                $email2 = mysql_escape_string($email2);
                $pass1 = mysql_escape_string($pass1);
                $pass2 = mysql_escape_string($pass2);

                mysql_query("INSERT INTO 'login' 
                                ('id', 'uname', email', 'pass') 
                        VALUES (NULL, '$uname', '$email1', '$pass1')") or die(mysql_error());

            }else{
                echo "Passwords do not match.<br />";
                exit();
            }
        }else{
            echo "Emails do not match.<br /><br />";
            exit();
        }
Run Code Online (Sandbox Code Playgroud)

有人可以把我推向正确的方向

亲切的问候,

vee*_*vee 5

对表名和列名使用返回刻度而不是单引号.请仔细阅读以获得进一步说明:http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

mysql_query("INSERT INTO `login` (`id`, `uname`, `email`, `pass`) VALUES (NULL, '$uname', '$email1', '$pass1')") or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)

只是为了指出其他问题,在您的查询中虽然"单引号"的使用不正确,但您在email列中缺少"单引号" .

另请注意,mysql_不推荐使用扩展程序,因此请继续查看实现mysqliPDO.