473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL

29
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 'sum( ) VALUES ()' at line 1

This is my code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //make conection
  3. $name=$_POST['name'];
  4. $cloth=$_POST['cloth'];
  5. $bag=$_POST['bag'];
  6.  
  7. $connection = mysql_connect("localhost", "root","") or die("Could not connect to MYSQL");
  8. $selection=mysql_select_db("addname") or die ("Unable to select database");
  9. $sql="SELECT * from sum WHERE name like '$name'"; 
  10. $result= mysql_query($sql) or die(mysql_error()); 
  11. $record = mysql_num_rows($result);  
  12.  
  13.    if ($record == 0)
  14.    {
  15.      $sql = "INSERT INTO sum( name, cloth, bag)  VALUES ('$name', '$cloth', '$bag')";
  16.       $result= mysql_query($sql);
  17.  
  18.      if ($result)
  19.      { echo "Record added: $name  $cloth  $bag "; }
  20.        else   { die(mysql_error()); }     
  21.    }
  22.    else
  23.      echo "<br>record already exist"; 
  24. ?>

can some 1 help me about this problem,
i used to fix it by changing the name, but now. it not success any more.
thz.
Jul 27 '09 #1
1 1991
Markus
6,050 Expert 4TB
In MySQL sum/SUM is a reserved word, that is, you cannot use it in a situation where it might be mistake for SQL syntax. The way to counter this is to surround any column-names table-names, etc., in backticks, like so:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO `tablename` (`field1`, `field2`, `field3`) VALUES (...)
  2.  
Also, Dreamy, please take a moment to read the Posting Guidelines - especially the part about 'how to post a question'. Use [code] tags when posting code.

Furthermore, questions go in the 'answers' sub-forum - not in the 'insights' sub-forum.

Mark.
Jul 27 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Wayne | last post by:
Hi, Can someone possibly assist me in finding the error in the following: echo "<p><strong>".($i+1).". Login: "; I get the following error returned when doing a syntax check PHP Parse...
1
by: beary | last post by:
Could someone please tell me what's wrong with the code below. It worked fine the first time, then I cleared the table (results) and tried it again, but got the message "You have an error in your SQL...
8
mmarif4u
by: mmarif4u | last post by:
Hi everybody... I want to enter values to db like the following,,, Format is like this (810605-14-6356) This is the rite format, No a to z letters... 6 digits then - then 2 digits then - then 4...
10
by: bobf | last post by:
I am using a program 'My Contact Table' which is a code generator program. It allows you to easily create a PHP/MySQL web application without writing any code. I am trying to create an additional...
4
by: FM | last post by:
Hi there: My question is about checking my sql-syntax against DB2UDB V9 throug JDBC 2.0 Is there a way to check my syntax,for example "select * from T1"? Thank you for your help. Regards,
6
by: zmee | last post by:
Hi, I'm doing a little game in OpenGL for college and I've got these 3 classes in C++: WarBalls - represents the Game's Application. It is supposed to be a singleton and holds all the Game's...
9
by: icemaster451 | last post by:
Hello im making a browser game and have 99% working but iv got one error i cant find / fix and would like to know if anyone can help me where im going wrong heres the error QUERY ERROR: You have an...
1
by: sathishauit | last post by:
<?php require_once ("inc/dbconnection.php"); class provider_function { public $select_query; public $select_result; public $insert_query; public $insert_result; public $update_query;
3
by: qdoet | last post by:
I'm newbie and I had a problem on my SQL syntax like this 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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.