The14thGOD Posted October 26, 2009 Share Posted October 26, 2009 I'm basically doing a truncate followed by a re-import of information, this will be set up as a cron job later using a CSV file, here's the error: 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 '00:00:00,2009-10-26 00:00:00,'M',2009-10-26 14:04:26)' at line 1 INSERT INTO Justin_Demographic VALUES(11111,2,'A','CMD','STATUS','NAME ','11111','EMAIL','PHONE','EXT ','ADDRESS','','US','CITY','COUNTY','STATE','ZIP','AB','ABC',0,500,2006-12-14 00:00:00,2009-10-26 00:00:00,'M',2009-10-26 14:04:26) Here's the PHP code to make it happen: <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $dbh = mysql_connect("localhost","user","pass"); mysql_select_db("db"); $fcontents = file ('./My_Demog.csv'); mysql_query("TRUNCATE Justin_Demographic"); $date = date("Y-m-d H:i:s"); for($i=0; $i<sizeof($fcontents); $i++) { $line = trim($fcontents[$i]); $arr = explode("|", $line); //, is the delimter $data = implode(',',$arr); $data = str_replace('"',"'",$data); $sql = "INSERT INTO Justin_Demographic VALUES ($data".','."$date) "; mysql_query($sql); if(mysql_error()) { echo mysql_error() ."<br>\n"; echo $sql; echo '<br /><br />'; echo $data; break; } } echo $i; ?> Sensitive data removed for obvious reasons. Thanks for any and all help, Justin Quote Link to comment https://forums.phpfreaks.com/topic/179096-error-in-query-cant-find-it/ Share on other sites More sharing options...
gizmola Posted October 26, 2009 Share Posted October 26, 2009 Yes, your dates are strings -- so they must be enclosed within quotes. Quote Link to comment https://forums.phpfreaks.com/topic/179096-error-in-query-cant-find-it/#findComment-944904 Share on other sites More sharing options...
The14thGOD Posted October 26, 2009 Author Share Posted October 26, 2009 That's what I thought at first but the CSV is being exported by phpMyAdmin, shouldn't that of put quotes around the dates? edit* I tried putting quotes around the date that I made and I still have the same error. I thought maybe my date was different or something, so thats why I tried this. Quote Link to comment https://forums.phpfreaks.com/topic/179096-error-in-query-cant-find-it/#findComment-944910 Share on other sites More sharing options...
gizmola Posted October 26, 2009 Share Posted October 26, 2009 Please post a describe of the table Justin_Demographic Quote Link to comment https://forums.phpfreaks.com/topic/179096-error-in-query-cant-find-it/#findComment-944916 Share on other sites More sharing options...
The14thGOD Posted October 26, 2009 Author Share Posted October 26, 2009 this looks sloppy, and it is, but I think it's what ur mainly asking for? int smallint varchar null varchar null varchar null varchar varchar null varchar null varchar null char null varchar null varchar null varchar null varchar null varchar null char null char null char null varchar null decimal(9,0) null decimal(9,0) null datetime null datetime null datetime Quote Link to comment https://forums.phpfreaks.com/topic/179096-error-in-query-cant-find-it/#findComment-944932 Share on other sites More sharing options...
The14thGOD Posted October 26, 2009 Author Share Posted October 26, 2009 hmm...there seems to be 25 cols of data in the query...but only 24 are in the database... Quote Link to comment https://forums.phpfreaks.com/topic/179096-error-in-query-cant-find-it/#findComment-944937 Share on other sites More sharing options...
gizmola Posted October 26, 2009 Share Posted October 26, 2009 Yeah, i need the names of the columns, but you get the idea. If you don't specify the order and number of columns on the insert ie. INSERT INTO tbl (col1, col2, col3 ...) VALUES (1, 2, 3... ) etc. then the values must exactly match the structure of the table. Quote Link to comment https://forums.phpfreaks.com/topic/179096-error-in-query-cant-find-it/#findComment-944949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.