|
Posted by Shelly on 11/08/07 17:08
Einstein30000 wrote:
> Hi,
>
> in one of my php-scripts is the following query (with an already open
> db-connection):
>
> $q = "INSERT INTO main (name, img, descr, from, size, format, cat,
> host, link, date) VALUES ('$name', '$img', '$descr', '$user', '$size',
> '$format', '$cat', '$host', '$link', '$date')" or die(mysql_error());
>
> And when the query gets executed i get back the following 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 'from, size, format, cat, host, link, date) VALUES ('bla', '-',
> 'keine', 'Holgi',' at line 1
>
> Whats wrong here?!
>
> cheers
Bypassing the constant back and forths herein this thread, let me say what I
do.
I format my query (as an example):
$q = "INSERT INTO Client (name, org_type, street1, street2, city, state, " .
"zip, mainPhone, county) " .
"VALUES (" .
GetSQLValueString($organization, "text") . ", " .
GetSQLValueString($orgTypeList, "text") . ", " .
GetSQLValueString($street1, "text") . ", " .
GetSQLValueString($street2, "text") . ", " .
GetSQLValueString($city, "text") . ", " .
GetSQLValueString(strtoupper($state), "text") . ", " .
GetSQLValueString($zip, "text") . ", " .
GetSQLValueString($mainPhone, "text") . ", " .
GetSQLValueString($county, "text") . ")";
(The GetSQLValueString is a function that does all the proper preparation
for the field.)
NOW, when I get an error, I also get a line number. If I still have
trouble, I do an echo $q, and I copy the resulting query. (Often, I see the
problem right here, though). I then go to the phpmyadmin and paste in that
query. I use the MySQL error tools to help find the problem. It is quicker
this way as I can adjust parameters there to get it to work. I then make
those mods required in my code to generate the correct query. In your case
it would have flagged the problem right away.
Shelly
[Back to original message]
|