0

我第一次尝试将大量数据写入 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 行有语法错误。经过一些研究,似乎查询可能太长了?如果是这样,我该如何缩短它,或者是否可以将它分解成块并运行多个查询?

正如我第一次尝试这样做时所说,如果我遗漏了一些基本的东西,我深表歉意。

干杯!

4

3 回答 3

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

应该

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

从那里开始,你错过了结束语'

于 2012-08-06T07:56:00.790 回答
1

在您的插入语句中,之后

'$_POST[DateOfCall]',

你忘了关闭你的简单报价

'$_POST[TimeOfCall]

只需关闭您打开的简单引号即可。

于 2012-08-06T07:56:06.987 回答
0

这是因为你必须在 php 中使用".这样的连接字符串:

$sql="INSERT INTO ...
VALUES ('".$_POST[Product]."','".$_POST[Region]."'....)"
于 2012-08-06T07:55:50.590 回答