pocobueno1388 Posted March 10, 2007 Share Posted March 10, 2007 I have a DATETIME field in the database that I am trying to stick a value in but keep getting an error. Here is my query: $insert_item = "INSERT INTO auctions (`ownerID`, `type`, `typeID`, `reserve`, `start`, `end`, `description`, `start_price`) VALUES ('$sid', '$item_type', '$itemID', '$reserve', $start, $end, '$description', ' $start_price')"; Here is the error I get: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '15:43, 2007-03-14 15:43, 'Pink dragon for your tank.', ' 500')' at line 2 And when I echo the query, I get this: INSERT INTO auctions (ownerID, type, typeID, reserve, start, end, description, start_price) VALUES ('-1', 'tankitem', '63570', '2000', 2007-03-10 15:43, 2007-03-14 15:43, 'Pink dragon for your tank.', ' 500') This happened when I started entering the dates/times into the DB. Any help is greatly appreciated, thanks =] Link to comment https://forums.phpfreaks.com/topic/42153-solved-inserting-custom-datetime-into-database-error/ Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 surround the date in # signs. IE: '#03-04-2007 00:00:00#' If it were me I wouldn't use the date/time field I would do it as an int of 11 and store the time() value in it, but if you want to look at the database like that periodically your way works to. To each his own. --FrosT Link to comment https://forums.phpfreaks.com/topic/42153-solved-inserting-custom-datetime-into-database-error/#findComment-204487 Share on other sites More sharing options...
pocobueno1388 Posted March 10, 2007 Author Share Posted March 10, 2007 EDIT: Hold on, I am an idiot...you can tell by my query, lmao. Nope, that didn't work either =/ Here is the query I used: $insert_item = "INSERT INTO auctions (`ownerID`, `type`, `typeID`, `reserve`, `#start#`, `#end#`, `description`, `start_price`) VALUES ('$sid', '$item_type', '$itemID', '$reserve', $start, $end, '$description', ' $start_price')"; Link to comment https://forums.phpfreaks.com/topic/42153-solved-inserting-custom-datetime-into-database-error/#findComment-204491 Share on other sites More sharing options...
pocobueno1388 Posted March 10, 2007 Author Share Posted March 10, 2007 Ugh, all I did was forget to put ' around my variables that held the date fields. Thanks for your time. Link to comment https://forums.phpfreaks.com/topic/42153-solved-inserting-custom-datetime-into-database-error/#findComment-204493 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.