简体   繁体   中英

php issue with inserting into sql

I am having an issue inserting into mysql db using php. specifically this code is giving me problems:

$sql = "INSERT INTO '$mysql_database'.'$UsersTable' ('firstName', 'lastName', 'password', 'email','userType')VALUES ('$firstName', '$lastName', '$password','$email','$userType')";

I can't seem to find the error with syntax here. All the information to me seems correct. where am I going wrong ?

try this

$sql = "INSERT INTO $mysql_database.$UsersTable (firstName, lastName, password, email,userType)VALUES ('$firstName', '$lastName', '$password','$email','$userType')";

remove Quote from table column

试试这个查询

$sql = "INSERT INTO $mysql_database.$UsersTable (firstName, lastName, password, email,userType)VALUES ('$firstName', '$lastName', '$password','$email','$userType')";

Hello you can't use single Quote from table column name so remove it

$sql = "INSERT INTO $mysql_database.$UsersTable (firstName, lastName, password, email,userType)VALUES ('$firstName', '$lastName', '$password','$email','$userType')";

otherwise use this way

$sql = "INSERT INTO $mysql_database.$UsersTable (`firstName`, `lastName`, `password`, `email`,`userType`)VALUES ('$firstName', '$lastName', '$password','$email','$userType')";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM