icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » MySQL syntax error, help!

PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >>

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old September 9th, 2004, 12:28 AM   #1 (permalink)
Registered User
Fresh Surpasser
 
Joined in Apr 2004
12 posts
Gave thanks: 0
Thanked 0 times
Question MySQL syntax error, help!

Hi,

I'm trying to enter some data into MySQL, but I keep getting this error:

PHP Code:
 
Error in query
INSERT INTO product (stock_numseriesnamethread_iddim_hdim_wdim_lweight, case) VALUES ('10999a''s12''test tein''325''123.6''123''423''123.67''4'). You have an error in your SQL syntaxCheck the manual that corresponds to your MySQL server version for the right syntax to use near 'case) VALUES ('10999a', 's12', 'Wulfe Stein', '325', '123.6', ' 
This is the structure of the 'product' table:
PHP Code:
   inv_id  int(255)  UNSIGNED No    auto_increment              
   stock_num  varchar
(255)   No                  
   series  varchar
(255)   No                  
   name  varchar
(255)   No                  
   thread_id  int
(255)  UNSIGNED No  0                
   dim_h  varchar
(255)   No  0                
   dim_w  varchar
(255)   No  0                
   dim_l  varchar
(255)   No  0                
   weight  varchar
(255)   No                  
   
case  varchar(10)   No  0 
Please help!
chap is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 9th, 2004, 12:34 AM   #2 (permalink)
I admire kayla
On a golden path...
 
Joined in Aug 2003
Lives in Saint Petersburg, Florida
Hosted on VPS5
478 posts
Gave thanks: 1
Thanked 1 Time in 1 Post
NEVERmnd
__________________
“The object of war is not to die for your country, but to make some other bastard die for his.” -George Patton
VPS5

Last edited by Unleashed2k; September 9th, 2004 at 12:47 AM.
Unleashed2k is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 9th, 2004, 5:28 PM   #3 (permalink)
Surpass Fan
Comfy Contributor
 
Joined in Apr 2004
Lives in Canada
Hosted on Pipe
141 posts
Gave thanks: 4
Thanked 3 times
PHP Code:
INSERT INTO `product` (`stock_num`, `series`, `name`, `thread_id`, `dim_h`, `dim_w`, `dim_l`, `weight`, `case`) VALUES ('10999a''s12''test tein''325''123.6''123''423''123.67''4'
Try this, maybe the word weight or case are reserved words for MYSQL. The `something`tells MYSQL to read this as an element of the table not a function.

Tell me if it works !
__________________
Website : max-worlds.net
Shared Server : Pipe
MadMax is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 10th, 2004, 12:49 AM   #4 (permalink)
Registered User
Fresh Surpasser
 
Joined in Apr 2004
12 posts
Gave thanks: 0
Thanked 0 times
Thanks for the suggestion MadMax, but I still get the error even after I put in the quotes.

I've changed weight and case to prod_weigh and prod_cas also, but that still gave me the same error. I thought series and name may also be reserved names, so i changed them to prod_nam and prod_s.

So, my query looks like this
PHP Code:
 
$queryprod 
"INSERT INTO _product ('stock_num', 'prod_s', 'prod_nam', 'thread_id', 'dim_h', 'dim_w', 'dim_l', 'prod_weigh', 'prod_cas') VALUES ('$prod_stocknum', '$prod_series', '$prod_name', '$t', '$prod_height', '$prod_width', '$prod_length', '$prod_weight', '$prod_case')";
$resultprod mysql_query($queryprod) or die ("Error in query: $queryprod. " mysql_error());; 
My table looks like this:

PHP Code:
   inv_id  int(255)  UNSIGNED No    auto_increment              
   stock_num  varchar
(255)   No                  
   prod_s  varchar
(255)   No                  
   prod_nam  varchar
(255)   No                  
   thread_id  int
(255)  UNSIGNED No  0                
   dim_h  varchar
(255)   No  0                
   dim_w  varchar
(255)   No  0                
   dim_l  varchar
(255)   No  0                
   prod_weigh  varchar
(255)   No                  
   prod_cas  varchar
(10)   No  0 
and my error looks like this:

Error in query: INSERT INTO product ('stock_num', 'prod_s', 'prod_nam', 'thread_id', 'dim_h', 'dim_w', 'dim_l', 'prod_weigh', 'prod_cas') VALUES ('10175', 's1a', 'frikken plabe', '325', '12.4', '123', '21', '12.6', '4'). 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 ''stock_num', 'prod_s', 'prod_nam', 'thread_id', 'dim_h', 'dim_w
I do't get it, it looks right to me, no matter how i look at it.

Please help!

Thanks!

Chap
chap is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 10th, 2004, 12:53 AM   #5 (permalink)
Web Hosting Super Ninj4
Super #1
 
miakeru's Avatar
 
Joined in Sep 2003
Lives in Fullerton, CA
1,581 posts
Gave thanks: 0
Thanked 2 times
Try removing the quotes in the first group, and removing the spaces between the commas.

On the next group, have single quotes and no spaces between the commas.

I've seen some cases where MySQL can be very picky of these things.
miakeru is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 10th, 2004, 1:07 AM   #6 (permalink)
Surpass Fan
Seasoned Poster
 
Joined in Aug 2004
Lives in North Carolina, USA
Hosted on Pass11
46 posts
Gave thanks: 0
Thanked 0 times
Use backticks ` around table and field names.
Use single quotes ' around values.
__________________
All your base are belong to us.
AngryPeasant is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 10th, 2004, 12:08 PM   #7 (permalink)
Registered User
Seasoned Poster
 
Scribe's Avatar
 
Joined in Aug 2004
84 posts
Gave thanks: 0
Thanked 0 times
You're missing a colon, at the end of the query it should be like ;";
Scribe is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 10th, 2004, 12:14 PM   #8 (permalink)
Registered User
Seasoned Poster
 
Scribe's Avatar
 
Joined in Aug 2004
84 posts
Gave thanks: 0
Thanked 0 times
This SHOULD work, you don't need ' or ` unless the names have spaces or wierd charactors, so you should always use the for WHAt you insert of course because you don't always know what it will be in DB systems:
PHP Code:
$queryprod "INSERT INTO product (stock_num, prod_s, prod_nam, thread_id, dim_h, dim_w, dim_l, prod_weigh, prod_cas) VALUES ('$prod_stocknum', '$prod_series', '$prod_name', '$t', '$prod_height', '$prod_width', '$prod_length', '$prod_weight', '$prod_case');"

$resultprod mysql_query($queryprod) or die ("Error in query: "mysql_error()); 

Last edited by Scribe; September 10th, 2004 at 12:23 PM.
Scribe is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 10th, 2004, 12:43 PM   #9 (permalink)
Surpass Fan
Seasoned Poster
 
Joined in Aug 2004
Lives in North Carolina, USA
Hosted on Pass11
46 posts
Gave thanks: 0
Thanked 0 times
According to PHP.net, the querystring should not end with a semicolon.

http://us4.php.net/mysql_query

Backticks are optional around table/field names (since he changed the field names to nonreserved words) but they won't hurt anything.

Single Quotes around values are a must though (except on numeric values, but it's still ok to use them).
__________________
All your base are belong to us.
AngryPeasant is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On