-3

I have Error the Syntax sql i have two data base and i used the query

$sqlinsert="insert into referent 
    (oldReferentId,genderReferent,firstnameReferent,lastnameReferent,
     emailReferent,phoneReferent,faxReferent,type,adressReferent,
     supportOrganization,zipCode,cityReferent,countryReferent,
     mailAverti,blocked,published,validateRight) 
   VALUES 
    (".$tb_user['id'].",'NULL',".$tb_user['name'].",".$tb_user['username'].",".
      $tb_user['email'].",'','',".$tb_user['usertype'].",'','s','z','c','cr','0',".
      $tb_user['block'].",'0','0')
";
$test=@mysql_query($sqlinsert,$db1) or die( mysql_error() . "<br>$sqlinsert" );

i get Error the Syntax ,how can i resolved That

Thanks

alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
  • 2
    What is the exact error? What is the query? – mrun Mar 12 '16 at 11:53
  • use quotes for string values, – devpro Mar 12 '16 at 12:02
  • **1.** That query was a mess, you should clean it up, so that it's easier to read. **2.** You are missing quotes around your strings. **3.** `mysql_*` functions are deprecated since PHP 5.5 (and **removed entirely** in PHP 7) and you should [stop using them](http://stackoverflow.com/q/12859942) if you can. You should choose another API that enables usage of prepared statements, like `mysqli_*` or PDO - see [choosing an API](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Qirel Mar 12 '16 at 12:02

1 Answers1

1

You are not using quotes for string value in your SQL Statement:

Issue in following location:

".$tb_user['name'].",".$tb_user['username'].",".$tb_user['email']."

Modified Statement:

$sqlinsert="insert into referent (oldReferentId,genderReferent,firstnameReferent,
lastnameReferent, emailReferent,phoneReferent,faxReferent,type,adressReferent,
supportOrganization,zipCode,cityReferent,countryReferent,mailAverti,blocked,published,validateRight) 
VALUES (".$tb_user['id'].",'NULL','".$tb_user['name']."',
'".$tb_user['username']."','".$tb_user['email']."','','',
'".$tb_user['usertype']."','','s','z','c','cr','0','".$tb_user['block']."','0','0')";

Side Note:

mysql_* extension is deprecated and close in PHP 7, please use mysqli_* or PDO.

devpro
  • 16,184
  • 3
  • 27
  • 38