473,831 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

29 New Member
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 2010
Markus
6,050 Recognized Expert Expert
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
1536
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 error: parse error, unexpected '>' in c:\wayne\results.php on line 37
1
1455
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 syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1". Problem is I can't see any " near line. And it worked fine the first time. What am I missing? Thankyou. <?php ...
8
1938
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 digits. dbConnect('db');
10
50035
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 data entry page. I have copied an existing page and created a new table in my database. When I run the script I get the error message "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right...
4
10766
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
5871
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 Managers. #ifndef WARBALLS_H #define WARBALLS_H #include "cg/cg.h"
9
2300
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 error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 0, '1', '2121221', '1212121', '12121', '12121', 1211, '121', 121)' at line 1 Query was INSERT INTO crimes (crimeNAME,...
1
1226
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
2315
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 '=1WHERE id_poll='1'' at line 1 The following below is my php code <?php include "inc.koneksi.php"; $IdDataH =$_POST; $Rbpilih =$_POST; $poll_sql ="SELECT * FROM polling WHERE id_poll='$IdDataH'"; $poll_qry =mysql_query($poll_sql, $konek)
0
9794
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10778
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10538
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10210
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9319
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5622
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3077
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.