我有错误语法sql我有两个数据库,我使用了查询
$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" );
我得到语法错误,我怎么解决那个
谢谢
答案 0 :(得分:1)
您没有在SQL语句中使用字符串值的引号:
以下位置发布:
".$tb_user['name'].",".$tb_user['username'].",".$tb_user['email']."
修改后的声明:
$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')";
旁注:
mysql_*
扩展名已弃用并在PHP 7中关闭,请使用mysqli_*
或PDO
。