Jump to content

error in query, can't find it...


The14thGOD

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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