homepage Welcome to WebmasterWorld Guest from 54.211.219.68
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Broken MySQL table
Can insert into one table in db but no another
topherknowles



 
Msg#: 4064353 posted 5:03 pm on Jan 20, 2010 (gmt 0)

Evening all, a little stumped.

I have a simple MySQL query as below that I am re-using from another page with different values:

$qry = "INSERT INTO match(matchdate,matchtime,opposition) VALUES('$matchdate','$matchtime','$opposition')";
$result = @mysql_query($qry);

However this returns the error message:

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 'match(matchdate,matchtime,opposition) VALUES('19/01/2009','19:00','Stoke')' at line 1

There are only 2 tables in the DB at present, if I change the table name and fields to the other one then it works fine.

Have checked all the connection settings / fieldnames and everything else I can think of, is it possible that a table could just simply not work?

 

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4064353 posted 7:56 pm on Jan 20, 2010 (gmt 0)

Match [dev.mysql.com] is a mysql function. You should avoid these types of names for two reasons, the first being the obvious conflict, the second, because the table names would be extremely easy to guess.

But a fix, should you choose to go with it, is to backtick the table name. This should do it.

$qry = "INSERT INTO `match` (matchdate,matchtime,opposition) VALUES('$matchdate','$matchtime','$opposition')";

topherknowles



 
Msg#: 4064353 posted 9:26 am on Jan 21, 2010 (gmt 0)

Ahhhh.... foiled by my limited MySQL vocabulary!

Thanks for that, would have been tearing my hair out for a long time attempting to google it.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved