开发者

What is wrong with this MySQL insert statement?

I am a beginning php/mysql developer, and I have wri开发者_开发知识库tten this statement to insert a username and password into a database to make an account. For some reason I am getting an error though; what's wrong?

mysql_query("INSERT INTO signup (Username, Password, Email) VALUES ($username, $password, $email)") or die ("cnnot run query");


Put quotes around the $username, $password and $email.

You should use prepared statements. Such usage is prone to SQL injections


Check your database connection code. Yes as Zimbabao suggested, always put quotes. here's sample.

//connect and select db
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("databasename") or die(mysql_error());

//Now Insert 
mysql_query("INSERT INTO signup (Username, Password, Email) VALUES ('$username', '$password', '$email')") or die(mysql_error());

The error you are showing is custom, if still getting error - please mention what does mysql_error() gives?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜