0

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

8
  • die('Error querying database.')-> trigger_error(mysqli_error().$query); Commented Apr 2, 2010 at 12:58
  • It would be helpful if you tell us which error you get :) Commented Apr 2, 2010 at 13:03
  • Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\xampp\htdocs\rob\report.php on line 43 Notice: INSERT INTO aliens_abduction (name, email) VALUES ('John', '[email protected]') in C:\xampp\xampp\htdocs\rob\report.php on line 43 Commented Apr 2, 2010 at 13:05
  • @user296516: Can you also post the corresponding code? It seems that you try to call mysqli_error() without passing any parameter. In the code you have given currently there is no mysqli_error(). Commented Apr 2, 2010 at 13:09
  • 2
    @user296516: You have to use it this way: mysqli_error($dbc). Commented Apr 2, 2010 at 13:23

6 Answers 6

3

seems that you've misspelled VALUES in your query.

Sign up to request clarification or add additional context in comments.

1 Comment

edited the typo, thanks. but still the same error keeps popping. :/
3

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')";

Comments

2

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

1 Comment

edited the typo, thanks. but still the same error keeps popping. :/
1
$query = "INSERT INTO aliens_abduction (name, email) VALUES ('John', '[email protected]')";

1 Comment

edited the typo, thanks. but still the same error keeps popping. :/
1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.