Re: mySQL Problem




"AnrDaemon" <anrdaemon@xxxxxxxxxxx> wrote in message
news:247167785.20071109125445@xxxxxxxxxxxxxx
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?

ask a dba in a db usenet group...or one at your company. :)

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.

no, it's an alias for an object really. but, yes, you can name it whatever
you wish. there is plenty of documentation in *every* db about avoiding such
conventions, esp. reserved words as dbo names, like the plague.

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.

so, you admit that mssql uses something DIFFERENT and PARTICULAR to alias?
you realize that your code becomes TIED to that db until you rewrite every
query to fit the NEXT db you want to use, don't you?

And I have no doubt that other server have identical solution for field
names.

no, only a reliable few share the same notation...and even fewer of those
are among the most commonly used dbs. next!

I think You are wrong and lack of proper quotation in field names isan
extension, not the quotation.

no, jerry is right. what you think is unimportant in light of what can be
cited and proven as correct...which we certainly can here in this case.

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

/agree

cheers


.



Relevant Pages

  • RE: Excel & MS Query caused compile errors
    ... My data is in an Excel file called ... The format of it were distorted after copying and pasting. ... Microsoft SQL Server 2000, which requires a server, VBA or Microsoft Query ...
    (microsoft.public.excel.programming)
  • Re: VBA ADO SQL Query Problem
    ... For long queries on a Oracle DB, I often meke it easy by using Business ... Object where I copy the SQL statement from. ... query parameter in the Oracle date format. ... But the query DID work, only no records were retrieved ...
    (microsoft.public.excel.programming)
  • Re: Ranking - dealing with ties
    ... I didn't think until too late just to post the SQL - sorry. ... qryDivScore has fields Score and Div. ... Alias Scor1) ... Alias has to be used instead of the actual query name, ...
    (microsoft.public.access.formscoding)
  • Re: Format issue ... 2 decimal places displayed?
    ... Jeanette Cunningham wrote: ... to get sql of your query, open the query in design view, then select Query | SQL view from the menu. ... you applied the format to the combo box. ...
    (microsoft.public.access.forms)
  • Re: Noob question - Data Type Mismatch
    ... I am fairly new to SQL and am running into a problem I can't figure ... this is the right place for the query so if not then let me know ... I get a "Data Type Mismatch in criteria expression" error. ... Your non-US format would work with the specific date value you specified because ...
    (microsoft.public.access.queries)