Reputation: 8538
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', '[email protected]')";
$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
Upvotes: 0
Views: 4560
Reputation: 762
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.
and also explanation and sample codes in this link will help you to display error messages relevant to the errors in your code.
Upvotes: 0
Reputation: 11
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', '[email protected]', '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.
Upvotes: 1
Reputation: 31
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')";
Upvotes: 3
Reputation: 120937
You have a typo in your query. Try changing VALUSE
to VALUES
.
Upvotes: 2
Reputation: 9815
$query = "INSERT INTO aliens_abduction (name, email) VALUES ('John', '[email protected]')";
Upvotes: 1