General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

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:
  #1  
Old October 23rd, 2003, 12:06 AM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 117 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 29 sec
Reputation Power: 6
SQL error

hi guys,

i encounter a problem when inserting a new row by using PHP

the 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 '' at line 1

my code:
<?
session_start();
include_once "include/db.php";
$result = mysql_query("INSERT INTO `items` ( `itemId` , `image` , `itemName` , `itemDesc` , `itemPrice` , `username` , `cat_status` , `update` ) VALUES ( '0', '$image', '$itemName', '$itemDesc', 'itemPrice', '".$_SESSION['username']."', '',''") or die(mysql_error());

For your information, itemId is an auto increment field and update is timestamp. I also try to insert the session value i registered in previous page into the username field in the db. I am wondering why i got such error even i copied the sql query exactly from phpmyadmin.

please advise.

Reply With Quote
  #2  
Old October 23rd, 2003, 12:31 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
First, you don't need itemId in your field list. It is an autoincrement field, so it will update either way.

Same deal for update... it will automatically get the current timestamp.

Take them out of your field list and your value statement.

Now, try it again. If it still doesn't work try putting the sql statement into a variable and output to the screen. That will allow us to debug the sql that is output.
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #3  
Old October 23rd, 2003, 12:47 AM
bubblocity bubblocity is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 2 bubblocity User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Did you check to see if you have any funky characters in the values of any of your variables ?
(i.e. in $image, $itemName, ...)

Depending on your server setting(MAGIC QUOTE setting), you might have to call addslashes to your variables, in case there are single quotes in the value of your variable, which will screw up your query.

If your $itemName = 'Brier's Ice Cream'

try calling: $itemName = addslashes($itemName)

result:
$itemName = 'Brier\'s Ice Cream'

Reply With Quote
  #4  
Old October 23rd, 2003, 02:43 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Good call bubblocity

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > SQL error


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 3 hosted by Hostway
Stay green...Green IT