Jump to content

Error querying database.


skiabox

Recommended Posts

I get the above error when trying to insert some values to a datatable.

Here's the code :

 

$dbc = mysqli_connect('127.0.0.1:3306', 'root', 'xxxx', 'aliendatabase')
or die('Error connecting to MySQL server.');

$query = "INSERT INTO aliens_abduction (first_name, last_name, " .
"when_it_happened, how_long, how_many, alien_description, " .
"what_they_did, fang_spotted, other, email) " .
"VALUES ('myFirstName', 'myLastName', '5 years ago', '2 years', '7 aliens', " .
"green eyes', 'we talked', " .
"'yes', 'none@gmail.com')";

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

mysqli_close($dbc);

 

Any ideas on what am I doing wrong?

Thank you very much.

Link to comment
Share on other sites

Your query failed.

 

"'green eyes You were missing a ' Try to get in the habit of writing your query code like this:

 

$statement = "INSERT INTO aliens_abduction ("
. "  first_name, last_name, when_it_happend, how_long,"
. "  how_many, alien_description, what_they_did,"
. "  fang_spotted, other, email"
. ") VALUES ("
. "  'firstname', 'lastname', '5 years ago', '2 years',"
. "  '7 aliens', 'green eyes', 'we talked',"
. "  'yes', '', 'none@gmail.com'"
. ")";

 

You were also missing an argument using this method you can spot this easily (the number of arguments per line equals the column names and the values:

 

first_name, last_name, when_it_happend, how_long,

'firstname', 'lastname', '5 years ago', '2 years',

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.