提交后PHP Sql查询错误

时间:2015-02-16 08:11:12

标签: php html

我的查询中出现错误,我想插入的条目是

这是我的代码

insertNew(1,"bob","johnson","brown","Jr",098765432123,"bobbrown@yahoo.com","1993-12-25",0)
function insertNew($empID,$fName,$mName,$lName,$suffix,$cellNum,$email,$birthDate,$pos)
 {
switch($pos)
{
    case 0:
    $query = "INSERT INTO vtiger_contactscf (cf_739,cf_703,cf_705) VALUES ($empID,'$mName','$suffix'); 
          INSERT INTO vtiger_contactdetails (firstname,lastname,email,contact_no) VALUES ('$fName','$lName','$email',$cellNum); 
          INSERT INTO vtiger_contactsubdetails (birthday) VALUES ('$birthDate'); ";
    $result = mysql_query($query) or die (mysql_error());
    echo "Registration for employee successful!";
    break;
}
}

我收到此错误

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   靠近'INSERT INTO vtiger_contactdetails   (名字,姓氏,电子邮件,contact_no)VALUES('第2行

3 个答案:

答案 0 :(得分:1)

试试这个......

Before // $empID to '$empID' in first query values

$query1 = "INSERT INTO vtiger_contactscf (cf_739,cf_703,cf_705) VALUES ('$empID','$mName','$suffix')"; 

    $result = mysql_query($query1) or die (mysql_error());

         $query2 = "INSERT INTO vtiger_contactdetails (firstname,lastname,email,contact_no) VALUES ('$fName','$lName','$email',$cellNum)"; 

    $result2 = mysql_query($query2) or die (mysql_error());

          $query3 = "INSERT INTO vtiger_contactsubdetails (birthday) VALUES ('$birthDate') ";
    $result3 = mysql_query($query3) or die (mysql_error());

OR

BEGIN;
INSERT INTO vtiger_contactscf (cf_739,cf_703,cf_705) VALUES ('$empID','$mName','$suffix');
INSERT INTO vtiger_contactdetails (firstname,lastname,email,contact_no) VALUES ('$fName','$lName','$email',$cellNum);
INSERT INTO vtiger_contactsubdetails (birthday) VALUES ('$birthDate');
COMMIT;

答案 1 :(得分:1)

不要在单行中使用多个查询...

只需编写一个并执行它,然后再写一个。

$query1 = "INSERT INTO vtiger_contactscf (cf_739,cf_703,cf_705) VALUES ('$empID','$mName','$suffix')"; 

mysql_query($query1) or die (mysql_error());

$query2 = "INSERT INTO vtiger_contactdetails (firstname,lastname,email,contact_no) VALUES ('$fName','$lName','$email',$cellNum)"; 

mysql_query($query2) or die (mysql_error());

$query3 = "INSERT INTO vtiger_contactsubdetails (birthday) VALUES ('$birthDate') ";
mysql_query($query3) or die (mysql_error());

答案 2 :(得分:0)

使用mysql通过php,你一次只能运行一个查询。这主要是出于安全原因,但您可以阅读here以获取其他解决方案。