Roger Travis
Roger Travis

Reputation: 8538

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', '[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

Answers (6)

Dushan
Dushan

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. enter image description here

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

karinashenaz
karinashenaz

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

Jane
Jane

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

Klaus Byskov Pedersen
Klaus Byskov Pedersen

Reputation: 120937

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

Upvotes: 2

Jimmy
Jimmy

Reputation: 9815

$query = "INSERT INTO aliens_abduction (name, email) VALUES ('John', '[email protected]')";

Upvotes: 1

parserr
parserr

Reputation: 729

seems that you've misspelled VALUES in your query.

Upvotes: 3

Related Questions