SQL查询错误“T_CONSTANT_ENCAPSED_STRING”错误

时间:2013-05-10 22:09:51

标签: php mysql sql

在下面的代码中,我错误地发出了T_CONSTANT_ENCAPSED_STRING错误

$query = "INSERT INTO Accounts (FirstName,LastName,Email,Phone,salt,passwd,City,State)   
    VALUES ('"
        . $_POST['FirstName'] . "','"
        . $_POST['LastName'] . "','"
        . $_POST['Email'] . "','"
        . $_POST['Phone'] . "','"
        . $salt . "','"
        . hashPasswd($_POST['passwd'], $salt "','"
        . ($_POST['City']
        . "','"
        . ($_POST['State'] . "'
    );

修改:感谢大家对此问题的所有帮助。对于这个可怜的问题感到抱歉,我当时是S / O的新手,并且没有读过how to ask a good question on S/O,我对此更为熟悉。再次感谢您的耐心等待。

2 个答案:

答案 0 :(得分:1)

您在行尾错过"

. ($_POST['State'] . "'"

和三个关闭)和一个.

    . hashPasswd($_POST['passwd'], $salt "','")
    . ($_POST['City'])
    . "','"
    . ($_POST['State'] . "'")
)

清理最后三行应如下所示:

    . hashPasswd($_POST['passwd'], $salt) ."','"
    . $_POST['City'] . "','"
    . $_POST['State'] . "'"
)

答案 1 :(得分:1)

试试这个。您错过了最后的"以关闭插入"。我打破了这些行,以便您可以轻松识别缺失的引号

  $query = "INSERT INTO Accounts (FirstName,LastName,Email,Phone,salt,passwd,City,State)   
        VALUES ('". $_POST['FirstName'] . "',
                '". $_POST['LastName'] . "',
                '". $_POST['Email'] . "',
                '". $_POST['Phone'] . "',
                '". $salt . "',
                '". hashPasswd($_POST['passwd'], $salt "',
                '". ($_POST['City']. "',
                '". ($_POST['State'] . "'
               )";