skiabox Posted December 26, 2009 Share Posted December 26, 2009 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 More sharing options...
ignace Posted December 26, 2009 Share Posted December 26, 2009 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', Link to comment https://forums.phpfreaks.com/topic/186374-error-querying-database/#findComment-984214 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.