我只是在这个SQL查询中找不到语法错误

时间:2012-07-01 14:12:40

标签: php mysql

你能告诉我这个查询有什么问题吗?我只是找不到错误,这让我疯了。

<?php
$query = "INSERT INTO atable (fortlaufend, vorname, nachname, land, email, caption1, caption2, caption3, caption4, caption5, datum) 
VALUES (NULL, 
" . mysql_real_escape_string($_POST[vorname]) . ", 
" . mysql_real_escape_string($_POST[nachname]) . ", 
" . mysql_real_escape_string($_POST[land]) . ", 
" . mysql_real_escape_string($_POST[email]) . ", 
" . mysql_real_escape_string($_POST[caption1]) . ", 
" . mysql_real_escape_string($_POST[caption2]) . ", 
" . mysql_real_escape_string($_POST[caption3]) . ", 
" . mysql_real_escape_string($_POST[caption4]) . ", 
" . mysql_real_escape_string($_POST[caption5]) . ", 
CURRENT_TIMESTAMP)";
?>

'fortlaufend'是AUTO_INCREMENT的主要索引。 mysql_error是

  

查询无效:您的SQL语法出错;查看与您的MySQL服务器版本相对应的手册,以便在“姓名,姓氏,国家/地区,电子邮件,使这张照片与您相称的特定内容”附近使用正确的语法,在第3行中使用Wha',

谢谢!

2 个答案:

答案 0 :(得分:5)

非整数值需要单引号。

  <?php
    $query = "INSERT INTO atable (fortlaufend, vorname, nachname, land, email, caption1, caption2, caption3, caption4, caption5, datum) 
    VALUES (NULL, 
    '" . mysql_real_escape_string($_POST[vorname]) . "', 
    '" . mysql_real_escape_string($_POST[nachname]) . "', 
    '" . mysql_real_escape_string($_POST[land]) . "', 
    '" . mysql_real_escape_string($_POST[email]) . "', 
    '" . mysql_real_escape_string($_POST[caption1]) . "', 
    '" . mysql_real_escape_string($_POST[caption2]) . "', 
    '" . mysql_real_escape_string($_POST[caption3]) . "', 
    '" . mysql_real_escape_string($_POST[caption4]) . "', 
    '" . mysql_real_escape_string($_POST[caption5]) . "', 
    CURRENT_TIMESTAMP)";
    ?>

答案 1 :(得分:1)

您的查询中没有使用引号。

<?php
$query = "INSERT INTO atable (fortlaufend, vorname, nachname, land, email, caption1, caption2, caption3, caption4, caption5, datum) 
VALUES (NULL, 
'" . mysql_real_escape_string($_POST[vorname]) . "', 
'" . mysql_real_escape_string($_POST[nachname]) . "', 
'" . mysql_real_escape_string($_POST[land]) . "', 
'" . mysql_real_escape_string($_POST[email]) . "', 
'" . mysql_real_escape_string($_POST[caption1]) . "', 
'" . mysql_real_escape_string($_POST[caption2]) . "', 
'" . mysql_real_escape_string($_POST[caption3]) . "', 
'" . mysql_real_escape_string($_POST[caption4]) . "', 
'" . mysql_real_escape_string($_POST[caption5]) . "', 
CURRENT_TIMESTAMP)";
?>