homepage Welcome to WebmasterWorld Guest from 54.166.84.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
MYSQL reoccuring problem
quozt

10+ Year Member



 
Msg#: 3473 posted 4:22 pm on Apr 11, 2004 (gmt 0)

i have re-written my code a few times and changed my database and am really confused i keep getting this error
"Could not add the entry because: 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 'desc, date_entered) VALUES (0, 'Maths', 'maths.php','this subje. The query was INSERT INTO admin (menu_id, name, link, desc, date_entered) VALUES (0, 'Maths', 'maths.php','this subject is maths', NOW())." when i try and insert the data into my database

any ideas

 

Birdman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3473 posted 4:34 pm on Apr 11, 2004 (gmt 0)

Most likely, it is because you named one of your fields with the reserved word, desc, which stands for descending and is used with the ORDER BY clause.

You can either rename the field or always enclose it in backticks(`) in your queries.

Example:
INSERT INTO admin (menu_id, name, link, `desc`, date_entered)

mapostel

10+ Year Member



 
Msg#: 3473 posted 4:34 pm on Apr 11, 2004 (gmt 0)

My best guess wwould be that the column name 'desc' would be a problem, as it is a reserved word in MySql (used for "ORDER BY"). See [dev.mysql.com ] for a list of reserved words.
Hope that helps ...

quozt

10+ Year Member



 
Msg#: 3473 posted 4:41 pm on Apr 11, 2004 (gmt 0)

changed it to description

Could not add the entry because: 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 '', date_entered) VALUES (0, 'adasd', 'asdasdasdas','dasdas', NO. The query was INSERT INTO admin (menu_id, name, link, description', date_entered) VALUES (0, 'adasd', 'asdasdasdas','dasdas', NOW()).

quozt

10+ Year Member



 
Msg#: 3473 posted 4:45 pm on Apr 11, 2004 (gmt 0)

and my php is

$query = "INSERT INTO admin (menu_id, name, link, description', date_entered) VALUES (0, '{$_POST['name']}', '{$_POST['link']}','{$_POST['descr']}', NOW())";

and mysql is

Field Type Attributes Null Default Extra Action
sub_id int(10) UNSIGNED No auto_increment
name text No
link text No
date_entered timestamp(14) Yes NULL
description text No
Check All / Uncheck All With selected:

mapostel

10+ Year Member



 
Msg#: 3473 posted 5:00 pm on Apr 11, 2004 (gmt 0)

one problem I see is that description has a single quote at the end. I reckon it should be completely without any quotes.

quozt

10+ Year Member



 
Msg#: 3473 posted 5:05 pm on Apr 11, 2004 (gmt 0)

cheers for that guys it works
woo hooo

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
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