Re: mySQL Problem



Greetings, Jerry Stuckle.
In reply to Your message dated Thursday, November 8, 2007, 16:31:15,

AnrDaemon wrote:
Greetings, Steve.
In reply to Your message dated Wednesday, November 7, 2007, 20:19:23,


"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 !!!

Agree but not in the way You think about.

hmmmm...perhaps you'll now see the
value in FORMATTING your queries where a HUMAN BEING can read it. makes it
easier to debug. :)

Actually, problem is proper quoting, not the format or anything else.

$sql = "
INSERT INTO main
(
`name` ,
`img` ,
`descr` ,
`from` ,
`size` ,
`format` ,
`cat` ,
`host` ,
`link` ,
`date`
)

That way. All should work now.



No, the REAL solution is to not use reserved words as column names.

Why if it's expected name for a column?
As far as field names is a strings, You can use any given name, even in Your
local encoding, and You can use spaces too.

Then you don't need the quotes - which, BTW, are a MySQL extension to
the SQL standard and won't work on any other RDBMS I'm familiar with.

MS SQL Server use square brackets in the same way.
And I have no doubt that other server have identical solution for field
names.
I think You are wrong and lack of proper quotation in field names isan
extension, not the quotation.

And it's better to ask SQL questions in a SQL newsgroup.

/agree


--
Sincerely Yours, AnrDaemon <anrdaemon@xxxxxxxxxxx>

.



Relevant Pages

  • Re: How to Set Datetime on SQL 2000 server
    ... I ran Query Analyzer on the SQL Enterprise Manager and ran: ... Windows 2000 server and the test 2003 server actually use US date format, ... regional settings, since you now are dependent on that as well. ...
    (microsoft.public.sqlserver.setup)
  • Re: Feldinhalt nach Aktualiserung formatieren
    ... > Auf dem SQL Server habe ich noch das Problem das er mir ... dass Du das Feld im Richtigen ... Format übergibst, am besten wandelst Du das einfach in eine Zahl um, ...
    (microsoft.public.de.access)
  • Re: Leading Zeros dropped in date returned from SQL Data using ASP
    ... It's not SQL that's formatting it, it's ASP, that's the relevant context. ... Actually, the value of that, in SQL Server, is 0x0000973C00000000; ... If you want to insure a specific format is used for that rendering, ... I have checked Short Date format in Regional Settings. ...
    (microsoft.public.inetserver.asp.db)
  • =?iso-8859-1?q?Re:_Anf=E4nger_und_ein_datetime_problem?=
    ... super das war es der style - 101 klappt mit convert perfekt!! ... hinterher auf einem US.Server laufen mit einem US SQL Server ... Kann sich das format je nach Installation/Settings (SQL ...
    (microsoft.public.de.sqlserver)
  • RE: Fulltext failure on a 2 node cluster
    ... Server full-text search resource online: "SQL Cluster Resource 'Full Text' ...
    (microsoft.public.sqlserver.clustering)