|
Posted by Steve on 11/07/07 17:19
"Einstein30000" <dominic_ernst@web.de> wrote in message
news:1194453026.587359.180320@19g2000hsx.googlegroups.com...
> 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?!
your sql statement is F.U.C.K.E.D !!! hmmmm...perhaps you'll now see the
value in FORMATTING your queries where a HUMAN BEING can read it. makes it
easier to debug. :)
$sql = "
INSERT INTO main
(
name ,
img ,
descr ,
from ,
size ,
format ,
cat ,
host ,
link ,
date
)
VALUES
(
'" . $name . "' ,
'" . $img . "' ,
'" . $descr . "' ,
'" . $from . "' ,
'" . $size . "' ,
'" . $format . "' ,
'" . $cat . "' ,
'" . $host . "' ,
'" . $link . "' ,
'" . $date . "'
)
";
well !!! lo-and-behold!!! when you get your error message back THIS time,
you actually get a line number OTHER THAN 1 !!! now THAT would be helpful!
imagine too, that you echo this out to the browser, copy it, and paste it
directly into your mysql query browser...then execute it. even before then,
you might have discovered (since you can now READ IT) that there is
something wrong in the data you're inserting.
don't let me throw you on that one...bad data is NOT the problem here. there
are things called RESERVED WORDS. one of those would be the word 'FROM'...as
in "select * FROM". if you had correctly formatted your sql statement, the
line number in error would have been line 6...a much better clue.
please put into use what has been well documented and implemented as 'best
practices', or, 'standards of practice'.
(what? so i have a pet peave about illegible code...bfd!)
[Back to original message]
|