williamZanelli Posted June 3, 2009 Share Posted June 3, 2009 Hi guys, I have an issue with "mysql_query" insert statments. I can extract data from my DB ie if I had a select query it works fine. Here the code for my "insert" query.. can anyone see what the prob may be? error_reporting(E_ALL); ini_set("display_errors", 1); $id = 773; $message = 'HAHahahahha'; $time = time(); $sql = "INSERT INTO messages (user, message, date_, up, down) VALUES($id, $message, null, 0, 0)"; $dbhost ='111.111.111.111'; $dbuser = 'dbuser'; $dbpass = 'mypass'; $dbname = 'dbname'; $con = mysql_connect($dbhost,$dbuser,$dbpass); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("webyolkco3", $con); $x = mysql_query($sql) or die("Couldn't execute query2. "); mysql_close($con); This always seems to be throwing a "Couldn't execute query2." message, any ideas? Thanks for your advice in advance Will Link to comment https://forums.phpfreaks.com/topic/160817-solved-mysql_query-insert-issue/ Share on other sites More sharing options...
Ken2k7 Posted June 3, 2009 Share Posted June 3, 2009 Your date column has an underscore in it? $sql = "INSERT INTO messages (user, message, date_, up, down) VALUES($id, '$message', null, 0, 0)"; Try that. Link to comment https://forums.phpfreaks.com/topic/160817-solved-mysql_query-insert-issue/#findComment-848749 Share on other sites More sharing options...
williamZanelli Posted June 3, 2009 Author Share Posted June 3, 2009 Ken2k7, Good job ;D Turned out that '$message' required the single quotes. The date does indeed have a underscore.. is that anti-convention? Thanks :-) Link to comment https://forums.phpfreaks.com/topic/160817-solved-mysql_query-insert-issue/#findComment-848758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.