第3行的MYSQL语法出错

时间:2012-08-06 07:53:18

标签: php mysql

我第一次尝试将大量数据写入MYSQL数据库。我正在使用以下插入查询:

if ($_POST['SubmitSave'] ) {
   $connection = mysql_connect($host, $user, $pass);
if (!$connection)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($db, $connection);

if ($_POST['SBI_CA001'] == NULL || $_POST['SBI_CA002'] == NULL || $_POST['SBI_CA003'] == NULL || $_POST['SBI_CA004'] == NULL || $_POST['SBI_CA004'] == NULL || $_POST['SBI_CA005'] == NULL || $_POST['SBI_CA006'] == NULL|| $_POST['SBI_CA007'] == NULL|| $_POST['SBI_CA008'] == NULL|| $_POST['SBI_CA009'] == NULL|| $_POST['SBI_CA010'] == NULL || $_POST['SBI_CA011'] == NULL|| $_POST['SBI_CA012'] == NULL|| $_POST['SBI_CA012'] == NULL|| $_POST['SBI_CA013'] == NULL || $_POST['SBI_CA014'] == NULL|| $_POST['SBI_CA015'] == NULL|| $_POST['SBI_CA016'] == NULL|| $_POST['SBI_CA017'] == NULL|| $_POST['SBI_CA018'] == NULL|| $_POST['SBI_CA019'] == NULL|| $_POST['SBI_CA020'] == NULL|| $_POST['SBI_CA021'] == NULL|| $_POST['SBI_CA022'] == NULL|| $_POST['SBI_CA023'] == NULL|| $_POST['SBI_CA024'] == NULL|| $_POST['SBI_CA025'] == NULL|| $_POST['SBI_CA026'] == NULL|| $_POST['SBI_CA027'] == NULL|| $_POST['SBI_CA028'] == NULL)
{
echo '<script type="text/javascript">'
   ,   'alert ( "Please Ensure All Questions have been marked before saving." );'
   , '</script>';   

}

else {
$sql="INSERT INTO Data_table (Product, Region, Area, BranchManager, BranchNum, SalesExec, DateofCall,TimeofCall,CallRef,CustName,CustDob,CustPostCode,Dept,QualityAnalyst,Tier,Score,Autofails,CA001Result,CA001Notes,CA001CustDet,CA002Result,CA002Notes,CA002CustDet,CA003Result,CA003Notes,CA003CustDet,CA004Result,CA004Notes,CA004CustDet,CA005Result,CA005Notes,CA005CustDet,CA006Result,CA006Notes,CA006CustDet,CA007Result,CA007Notes,CA007CustDet,CA008Result,CA008Notes,CA008CustDet,CA009Result,CA009Notes,CA009CustDet,CA010Result,CA010Notes,CA010CustDet,CA011Result,CA011Notes,CA011CustDet,CA012Result,CA012Notes,CA012CustDet,CA013Result,CA013Notes,CA013CustDet,CA014Result,CA014Notes,CA014CustDet,CA015Result,CA015Notes,CA015CustDet,CA016Result,CA016Notes,CA016CustDet,CA017Result,CA017Notes,CA017CustDet,CA018Result,CA018Notes,CA018CustDet,CA019Result,CA019Notes,CA019CustDet,CA020Result,CA020Notes,CA020CustDet,CA021Result,CA021Notes,CA021CustDet,CA022Result,CA022Notes,CA022CustDet,CA023Result,CA023Notes,CA023CustDet,CA024Result,CA024Notes,CA024CustDet,CA025Result,CA025Notes,CA025CustDet,CA026Result,CA026Notes,CA026CustDet,CA027Result,CA027Notes,CA027CustDet,CA028Result,CA028Notes,CA028CustDet)
VALUES
('$_POST[Product]','$_POST[Region]','$_POST[Area]','$_POST[BranchManager]','$_POST[BranchNum]','$_POST[SalesExecs]','$_POST[DateOfCall]','$_POST[TimeOfCall],'$_POST[CallRef],'$_POST[CustName],'$_POST[CustDoB],'$_POST[CustPostcode],'$_POST[SwintHunts],'$_POST[QualityAnalyst]',$_POST[Tier],'$_POST[Result_Score],'$_POST[Result_AutoFail],'$_POST[SBI_CA001],'$_POST[SBI_CA001_Text],'$_POST[SBI_CA001_CustDet],'$_POST[SBI_CA002],'$_POST[SBI_CA002_Text],'$_POST[SBI_CA002_CustDet],'$_POST[SBI_CA003],'$_POST[SBI_CA003_Text],'$_POST[SBI_CA003_CustDet],'$_POST[SBI_CA004],'$_POST[SBI_CA004_Text],'$_POST[SBI_CA004_CustDet],'$_POST[SBI_CA005],'$_POST[SBI_CA005_Text],'$_POST[SBI_CA005_CustDet],'$_POST[SBI_CA006],'$_POST[SBI_CA006_Text],'$_POST[SBI_CA006_CustDet],'$_POST[SBI_CA007],'$_POST[SBI_CA007_Text],'$_POST[SBI_CA007_CustDet],'$_POST[SBI_CA008],'$_POST[SBI_CA008_Text],'$_POST[SBI_CA008_CustDet],'$_POST[SBI_CA009],'$_POST[SBI_CA009_Text],'$_POST[SBI_CA009_CustDet],'$_POST[SBI_CA010],'$_POST[SBI_CA010_Text],'$_POST[SBI_CA010_CustDet],'$_POST[SBI_CA011],'$_POST[SBI_CA011_Text],'$_POST[SBI_CA011_CustDet],'$_POST[SBI_CA012],'$_POST[SBI_CA012_Text],'$_POST[SBI_CA012_CustDet],'$_POST[SBI_CA013],'$_POST[SBI_CA013_Text],'$_POST[SBI_CA013_CustDet],'$_POST[SBI_CA014],'$_POST[SBI_CA014_Text],'$_POST[SBI_CA014_CustDet],'$_POST[SBI_CA015],'$_POST[SBI_CA015_Text],'$_POST[SBI_CA015_CustDet],'$_POST[SBI_CA016],'$_POST[SBI_CA016_Text],'$_POST[SBI_CA016_CustDet],'$_POST[SBI_CA017],'$_POST[SBI_CA017_Text],'$_POST[SBI_CA017_CustDet],'$_POST[SBI_CA018],'$_POST[SBI_CA018_Text],'$_POST[SBI_CA018_CustDet],'$_POST[SBI_CA019],'$_POST[SBI_CA019_Text],'$_POST[SBI_CA019_CustDet],'$_POST[SBI_CA020],'$_POST[SBI_CA020_Text],'$_POST[SBI_CA020_CustDet],'$_POST[SBI_CA021],'$_POST[SBI_CA021_Text],'$_POST[SBI_CA021_CustDet],'$_POST[SBI_CA022],'$_POST[SBI_CA022_Text],'$_POST[SBI_CA022_CustDet],'$_POST[SBI_CA023],'$_POST[SBI_CA023_Text],'$_POST[SBI_CA023_CustDet],'$_POST[SBI_CA024],'$_POST[SBI_CA024_Text],'$_POST[SBI_CA024_CustDet],'$_POST[SBI_CA025],'$_POST[SBI_CA025_Text],'$_POST[SBI_CA025_CustDet],'$_POST[SBI_CA026],'$_POST[SBI_CA026_Text],'$_POST[SBI_CA026_CustDet],'$_POST[SBI_CA027],'$_POST[SBI_CA027_Text],'$_POST[SBI_CA027_CustDet],'$_POST[SBI_CA028],'$_POST[SBI_CA028_Text],'$_POST[SBI_CA028_CustDet])";

if (!mysql_query($sql,$connection))
  {
  die('Error: ' . mysql_error());
  }

然而,它正在传达一条消息,我在第3行上已经使用了语法。经过一些研究,似乎查询可能太长了?如果是这样,我该如何缩短它,或者是否可以将其分解为块并运行多个查询?

正如我所说的那样,如果我遗漏了一些基本的东西,那么第一次尝试这么道歉。

干杯!

3 个答案:

答案 0 :(得分:3)

'$_POST[TimeOfCall],'$_POST[CallRef]

应该是

'$_POST[TimeOfCall]','$_POST[CallRef]',...
从那以后,你错过了收尾报价&#39;

答案 1 :(得分:1)

之后的插入语句中的

'$_POST[DateOfCall]',

你忘了关闭简单的引语

'$_POST[TimeOfCall]

只需关闭你的opend简单引号。

答案 2 :(得分:0)

这是因为你必须使用".在php中连接字符串,如下所示:

$sql="INSERT INTO ...
VALUES ('".$_POST[Product]."','".$_POST[Region]."'....)"