2013-10-13 34 views
0

試圖運行此插入查詢錯誤我只是不明白,MYSQL PDO PHP

$query = $pdo->prepare("INSERT INTO `contacts` (`id`, `firstname`, `lastname`, `phonenumber`, `rank`, `time`) VALUES (NULL, :firstname, :lastname, :authcode, '1', NOW()"); 
$query->execute(array(":firstname" => $firstname, ":lastname" => $lastname, ":phone" => $phone)); 
$message[1] = '<font color=lime>Successfully added!</font>'; 

我得到這個錯誤:

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[42000]: Syntax error or access violation: 1064 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 '' at line 1 in /public_html/contacts/add.php on line 61

($query->execute(array...)是線61

回答

3

你查詢不正確,這就是爲什麼你收到語法錯誤。你錯過了結局)

INSERT INTO contacts (
    id, 
    firstname, 
    lastname, 
    phonenumber, 
    rank, 
    time 
) VALUES (
    NULL, 
    :firstname, 
    :lastname, 
    :phone, 
    '1', 
    NOW() 
) 

格式化查詢後,發現這種錯誤更容易。

+0

謝謝我在發佈後明白了,但再次感謝您的幫助。 – Swaly

+0

你甚至沒有:電話在你的查詢中,你有:authcode而不是電話 – geryjuhasz

+0

@geryjuhasz很好,所以在那個查詢中還有一個錯誤。 –