php mySQL插入问题

时间:2011-06-04 15:06:35

标签: php mysql

你在这次插入中看到了什么问题吗?

它对我不起作用..

$insSubm = "INSERT INTO cR_Submissions memberID ='".$memberID."', RefNumb='".$RefNumb."', title ='".$title."', CopyRightNumb='".$copyRightNumbWork."', type='".$natureTypeWork."', OtherTitle='".$alternateTitleWork."', OwnershipTransfer='".$textareaPrior."', Status ='".$status."', DateWhen='".$todaydate."', Time='".$NowisTime."'";
$resultinsSubm=mysql_query($insSubm) or die("Error insert Submissions: ".mysql_error());

我是瞎了吗?

请帮忙

由于

3 个答案:

答案 0 :(得分:4)

这是无效的SQL语法。 SQL语法是:

INSERT INTO table (field1, field2, ..., fieldN) VALUES (val1, val2, ..., valN)

另一种MySQL语法是:

INSERT INTO table SET field1 = val1, field2 = val2, ..., fieldN = valN

您错过了SET关键字。查看INSERT Syntax文档了解更多相关信息。

答案 1 :(得分:0)

查询应该是......

$insSubm = "
  INSERT INTO `cR_Submissions` (`memberID`, ...)
  VALUES ('" . $memberID . "', ... )";

答案 2 :(得分:0)

使用以下代码更改您的代码:

$insSubm = "INSERT INTO cR_Submissions (memberID, RefNumb, title, CopyRightNumb, type, OtherTitle, OwnershipTransfer, Status, DateWhen, Time) 
            VALUES ('$memberID', '$RefNumb', '$title', '$copyRightNumbWork', '$natureTypeWork', '$alternateTitleWork', '$textareaPrior', '$status', '$todaydate', '$NowisTime');";

$resultinsSubm = mysql_query($insSubm) or die("Error insert Submissions: ".mysql_error());