Re: mySQL Problem




"Einstein30000" <dominic_ernst@xxxxxx> wrote in message
news:1194453026.587359.180320@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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!)


.



Relevant Pages

  • Re: MakeTable Query -- Field Must be "Double" vs. "Decimal"
    ... You will still need to open your table in design view, and set the Format to ... > In a "MakeTable" query, I use an expression that calculates the following ... > When I execute the query, field "Total" always becomes a "Decimal" data ...
    (microsoft.public.access.queries)
  • RE: inserting a dash
    ... intermediate query to change the format. ... update query using the new table but the query still did not execute. ...
    (microsoft.public.access.queries)
  • Query with contents of text file.
    ... Now I want to execute against a database a query in the format ...
    (comp.databases.oracle.misc)
  • Re: "Select" & "Order By" OK- WHERE Doesnt Work !
    ... The error message was "could not execute query". ... format' 'artist'. ...
    (comp.lang.php)
  • Re: formatting a calculated number field on a form
    ... > A query in an MDB file CAN call a user-defined function. ... > function name is Age and it returns a double. ... The user will certainly "notice" if a patient was born on Jan ... I just want control over the *display format* of a number ...
    (microsoft.public.access.forms)