Forum Moderators: coopster

Message Too Old, No Replies

Cannot get data loaded into MySQL Table

You have an error in your SQL syntax

         

cochranrg

8:30 pm on Apr 13, 2006 (gmt 0)

10+ Year Member



Just starting to try to figure out MySQL. Trying to load some data into a table. Here is the code:

$db_name = "premiers_listings";
$table_name = "art";
$connection = mysql_connect("localhost","account","password") or die ("MySQL Connection Error.");
$db = mysql_select_db($db_name, $connection) or die ("MySQL DbName Error.");
$sql = "INSERT INTO $table_name VALUES (".$meminfo[0].", ".$meminfo.", ".$meminfo[2].", ".$meminfo[3].", ".$meminfo[4].", ".$meminfo[5].", ".$meminfo[6].", ".$meminfo[7].", ".$meminfo[8].", ".$meminfo[9].", ".$meminfo[10].", ".$meminfo[11].", ".$meminfo[12].", ".$meminfo[13].", ".$meminfo[14].", ".$meminfo[15].", ".$meminfo[16].", ".$meminfo[17].", ".$meminfo[18].", ".$meminfo[19].", ".$meminfo[20].", ".$meminfo[21].", ".$meminfo[22].", ".$meminfo[23].", ".$meminfo[24].", ".$meminfo[25].", ".$meminfo[26].", ".$_COOKIE["verify"].", ".(date(m)."/".date(d)."/".date(y)).", ".$meminfo[27].")";
$result = mysql_query($sql,$connection) or die("MySQL SQL,Connection Error.\n".mysql_error());

I get good connect etc., but always get this 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 'art,trash art,6.99,1.99,19.99,FedEx,30,http://www.example.com

$meminfo[x] is data pulled out of an uploaded tab delimited file and contains:

33221 \t Trash \t Art \t Trash art \t trash art \t 6.99 \t 1.99 \t 19.99 \t FedEx \t 30 \t http://www.example.com/visa_small.gif \t http://www.example.com/visa_med.gif \t http://www.example.com/visa_small.gif \t http://www.example.com/visa_small.gif \t 1 \t 1 \t 1 \t 1 \t 1 \t 1 \t 1 \t 1 \t 1 \t 1 \t 1 \t 1 \t 1 \t username \t 3.11.06 \t http://www.example.com
(I inserted \t so you could tell where tabs are).

Gotta be something stupid, but I don't have a clue at the time. All table fields are set to TEXT.

[1][edited by: jatar_k at 8:51 pm (utc) on April 13, 2006]
[edit reason] fixed sidescroll [/edit]

cochranrg

8:47 pm on Apr 13, 2006 (gmt 0)

10+ Year Member



Some additional information. The first field of my table is set to INT and AUTO INCREMENT. I'm not really sure how to put this into my Table Loading line:

$sql = "INSERT INTO $table_name VALUES (,".$meminfo[0].",".$meminfo[1].",".$meminfo[2].",".$meminfo[3].",".$meminfo[4].")";

This is the latest I've tried. Now I'm seeing the first two fields in the error message that I have not seen before...

MySQL SQL,Connection 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 '33221,Trash,Art,Trash art,trash art)' at line 1

Still plutzing around with it. Any ideas greatly appreciated!

RC

jatar_k

8:50 pm on Apr 13, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



for your auto inc field you can just add paired single quotes with nothing in them

$sql = "INSERT INTO $table_name VALUES ('',".$meminfo[0].",".$meminfo[1].",".$meminfo[2].",".$meminfo[3].",".$meminfo[4].")";

cochranrg

9:14 pm on Apr 13, 2006 (gmt 0)

10+ Year Member



I have changed the input line to:

$sql = "INSERT INTO $table_name VALUES ('',".$meminfo[0].",".$meminfo[1].",".$meminfo[2].",".$meminfo[3].",".$meminfo[4].")";

Now I get a little different error, not showing my first two fields:

MySQL SQL,Connection 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 'art,trash art)' at line 1

whoisgregg

9:22 pm on Apr 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to have quotes around your strings:

$sql = "INSERT INTO $table_name VALUES ('', '".$meminfo[0]."' , '".$meminfo[1]."' , '".$meminfo[2]."' , '".$meminfo[3]."' , '".$meminfo[4]."' )";

cochranrg

9:32 pm on Apr 13, 2006 (gmt 0)

10+ Year Member



Gregg, you are so the man. This seems to be working!

Thanks,
RC