MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 1st, 2004, 04:23 PM
Forsaken Forsaken is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 5 Forsaken User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Using PHP, mysql_query INSERT failing, I'm stumped.

It's been about a year since I've done any PHPMySQL and I'm stuck on this one query trying to get some data inserted into my table.

Here are the details, any help would be appreciated.

I'm getting data from a form via the POST method. I verified that all the data is coming through from submit.php into my index.php file.

Here is the query:
Code:
mysql_query ( "INSERT INTO hardware (serial, atag, pdate, desc, dept, user) VALUES ('".$_POST['serial']."','".$_POST['atag']."','".$finaldate."','".$_POST['desc']."','".$_POST['dept']."','".$_POST['user']."')") or die (mysql_error());


At one time I had the query setup like this which has worked for me in the past:
Code:
mysql_query ( "INSERT INTO hardware (serial, atag, pdate, desc, dept, user) VALUES ('{$_POST['serial']}','{$_POST['atag']}','$finaldate','{$_POST['desc']}','{$_POST['dept']}','{$_POST['user']}')") or die (mysql_error());


Both give the same results.

Here is the error:
Quote:
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, dept, user) VALUES ('6785551212','SOLI-1001','2004-12-01'

The syntax looks right to me, so I don't understand where the problem is.


I'm running MySQL 4.0.14-nt on a Windows Server 2003 box.
PHP v4.3.2

Reply With Quote
  #2  
Old June 1st, 2004, 07:34 PM
digitalamit digitalamit is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: New Delhi, India
Posts: 19 digitalamit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to digitalamit Send a message via AIM to digitalamit Send a message via Yahoo to digitalamit
Just put the field names in tick (`) like

PHP Code:
 mysql_query "INSERT INTO hardware (`serial`, `atag`, `pdate`, `desc`, `dept`, `user`) VALUES 
('{$_POST['serial']}','{$_POST['atag']}','$finaldate','{$_POST['desc']}','{$_POST['dept']}','{$_POST['user']}')"
) or die (mysql_error()); 


HTH!

Reply With Quote
  #3  
Old June 2nd, 2004, 12:22 PM
Forsaken Forsaken is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 5 Forsaken User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I figured out my problem. Apparently, when I was refering to "desc" something in mysql or php didnt like it. I canged desc to details and renamed it in my table and changed it in the code and everything works fine. Maybe desc is some type of reserved word or maybe I used it somewere else in my code for something else. Anyway, It works now.

Reply With Quote
  #4  
Old June 2nd, 2004, 02:06 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Ah, I can't believe that didn't jump out at me. I've had similar keyword problems before myself. Desc is used to modify the order by clause and so can't be used as a field name.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #5  
Old June 2nd, 2004, 02:26 PM
Forsaken Forsaken is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 5 Forsaken User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Now that you've said that, it's all coming back to me now. This is day 3 after an extended break from anything PHP MySQL related.

I find myself looking at code I wrote a year ago, and its taking me a good 20-30 minutes to figure out what I was doing. It looks like was good back then, I can't even believe that I wrote some of the code that I'm looking at. It's going to take me a month to get as comfortable as I was. I'm glad I ran across these boards. I can use them as a little crutch while I'm getting back into the swing of things.

Reply With Quote
  #6  
Old June 5th, 2004, 07:30 AM
digitalamit digitalamit is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: New Delhi, India
Posts: 19 digitalamit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to digitalamit Send a message via AIM to digitalamit Send a message via Yahoo to digitalamit
That is why you should always enclose the table name and field names with tick(`)

Reply With Quote
  #7  
Old June 19th, 2004, 12:04 PM
Selleri Selleri is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Iceland
Posts: 46 Selleri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 sec
Reputation Power: 6
Maybe you should start commenting the trickier parts of your code

Reply With Quote
  #8  
Old June 20th, 2004, 01:52 PM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 5
Send a message via MSN to Pheifel
using the (`) does absolutely no difference what so ever!.... you can still not use keywords like: "desc", "asc", "where", "for", "and" or any other words used in the mysql syntax to alter the querys from it. or within it.
- pheifel

Reply With Quote
  #9  
Old June 25th, 2004, 07:04 PM
psostre psostre is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 1 psostre User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Wink

Quote:
Originally Posted by Pheifel
using the (`) does absolutely no difference what so ever!.... you can still not use keywords like: "desc", "asc", "where", "for", "and" or any other words used in the mysql syntax to alter the querys from it. or within it.
- pheifel

not true, I've been able to use

SELECT * FROM whatever WHERE `desc` LIKE ...

successfully...

Regards,
Pedro

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Using PHP, mysql_query INSERT failing, I'm stumped.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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 not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway