开发者

Error querying database in PHP, MySQL

I have this code in PHP. It connects to the DB fine, but pops an error, when tryinto to insert the info.

$dbc = mysqli_connect('localhost', 'root', 'marina', 'aliendatabase') or die('Error connecting to MySQL server.');

$query = "INSERT INTO aliens_abduction (name, email) VALUSE ('John', 'john@e开发者_如何学Cverynet.gov')";

$result = mysqli_query($dbc, $query) or die('Error querying database.');
mysqli_close($dbc);

Here's a screenshot: http://img532.imageshack.us/img532/2930/63306356.jpg

Thanks, R


seems that you've misspelled VALUES in your query.


Try this:

$query = "INSERT INTO aliens_abduction (name, email, when_did_it_happen, what_did_they_do, " . "seen_Fang", "anything_else") VALUES ($'name', '$email', '$when_did_it_happen',". "'$what_did_they_do', '$seen_Fang', '$anything_else')";


You have a typo in your query. Try changing VALUSE to VALUES.


$query = "INSERT INTO aliens_abduction (name, email) VALUES ('John', 'john@everynet.gov')";


I think you need to write something along the lines of...

$query = "INSERT INTO aliens_abduction (name, email, when_did_it_happen, what_did_they_do, " .
"seen_Fang", "anything_else") VALUES ('John', 'john@everynet.gov', 'tuesday', 'nothing', 'no', ' ')";

When you insert data into the table, you need to specify every row you have in that table in the brackets before the Values...

By now you have probably found out the answer for yourself :P However for others that may have a similar error (such as myself) may find this information useful.


I was doing the same exercise from Headfirst PHP & MYSQL and got the same error and figured out why this happened. In my end, this happened just because I had filled one of the form field with a text containing apostrophe ( ' ). I have circled that text in Red color in below screenshot. Hope this helps someone to go ahead.

Error querying database in PHP, MySQL

and also explanation and sample codes in this link will help you to display error messages relevant to the errors in your code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜