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', '[email protected]')";

$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
https://forums.phpfreaks.com/topic/186374-error-querying-database/
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', '', '[email protected]'"
. ")";

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.