1

I'm having an error in my query the entries that I wanna are insert are

Here is my code

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;
}
}

I'm receiving this error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO vtiger_contactdetails (firstname,lastname,email,contact_no) VALUES (' at line 2

Bob
  • 1,489
  • 1
  • 16
  • 28
user3911182
  • 39
  • 1
  • 9

3 Answers3

1

Try this...

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;
Deenadhayalan Manoharan
  • 5,436
  • 14
  • 30
  • 50
1

Don't use multiple queries in single line...

Just write one and execute it, then write another.

$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());
Deenadhayalan Manoharan
  • 5,436
  • 14
  • 30
  • 50
Punit
  • 450
  • 3
  • 11
0

With mysql through php you will only be able to run one query at a time. This is mostly done for security reasons, but you can read about it here for alternate solutions.

Community
  • 1
  • 1