473,396 Members | 2,139 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,396 software developers and data experts.

error in your SQL syntax

hi....i am doing a php project.but lately, i have been in a dilemma bcoz i am receiving this kind of error after hitting the submit button.

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


this is my coding.....

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /* include db connection file */
  3. include("dbconn.php");
  4. if(isset($_POST['submit']))
  5. {
  6. /* capture values from HTML form */
  7. $icnumber = $_POST['icnumber'];
  8. $name = $_POST['name'];
  9. $position = $_POST['position'];
  10. $department = $_POST['department'];
  11. $email = $_POST['email'];
  12. $phoneno = $_POST['phoneno'];
  13. $username = $_POST['username'];
  14. $password = $_POST['password'];
  15.  
  16. $sql0 = "SELECT stafficnumber FROM staff WHERE stafficnumber= $icnumber";
  17. $query0 = mysql_query($sql0) or die ("Error: " . mysql_error());
  18. $row0 = mysql_num_rows($query0);
  19. if($row0 != 0)
  20. {
  21. echo "Record is existed";
  22. }
  23. else
  24. {
  25. /* execute SQL INSERT command */
  26. $sql2 = "INSERT INTO staff ( stafficnumber, staffname, staffposition, staffdepartment, staffemail, staffphoneno, staffusername, staffpassword )
  27. VALUES ('".$icnumber."','".$name."',','".$position."','".$department."','".$email."','".$phoneno."''".$username."','".$password."')";
  28. mysql_query($sql2) or die ("Error: ".mysql_error());
  29. /* display a message */
  30. echo "Data has been saved";
  31. }
  32. }// close if isset()
  33. /* close db connection */
  34. mysql_close($dbconn);
  35. ?>
  36.  
i have re-write this code but the error still appear after i hit the submit button. i'm very glad if anyone could help me plz....
Nov 29 '11 #1

✓ answered by zorgi

Generally that error means that something is wrong with your SQL syntax. I can see couple of things wrong with your $sql2 but there may be more.

You are missing comma here:

Expand|Select|Wrap|Line Numbers
  1. ".$phoneno."''".$username."
should be:

Expand|Select|Wrap|Line Numbers
  1. ".$phoneno."','".$username."
And you have problem with commas here too:

Expand|Select|Wrap|Line Numbers
  1. .$name."',','".$position.
It’s a good idea to echo your SQL statements for debugging.

2 1181
zorgi
431 Expert 256MB
Generally that error means that something is wrong with your SQL syntax. I can see couple of things wrong with your $sql2 but there may be more.

You are missing comma here:

Expand|Select|Wrap|Line Numbers
  1. ".$phoneno."''".$username."
should be:

Expand|Select|Wrap|Line Numbers
  1. ".$phoneno."','".$username."
And you have problem with commas here too:

Expand|Select|Wrap|Line Numbers
  1. .$name."',','".$position.
It’s a good idea to echo your SQL statements for debugging.
Nov 29 '11 #2
thank you for helping me.....
Nov 30 '11 #3

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

Similar topics

3
by: Balaji | last post by:
I'm trying to do some basic socket programming. here is the line of code which is creating problem.. int FAR PASCAL __declspec (dllexport)(char * addr,int port) Hers is the error I'm...
2
by: kalpana.sinduria | last post by:
Hi all, how to remove the following complle error. When I compiling the code I get the following errors: Compiling... CDrtEachDefFeat.cpp d:\ include\common\cdrtintegfeat.h(39) : error...
0
by: MWK | last post by:
Hi All, I don't understand why I get "error c2061: syntax error : identifier" in VS2003. I thought it's fixed in .Net 2003: __hook(&TCP_Client::LineReceived, client, HandlerLineReceived); ...
1
by: IceColdFire | last post by:
I have a VC++.net Win32 console application, however when I compile , I get this error error C2146: syntax error : missing ';' before identifier 'Length' Explain... Location pointed is ...
1
by: parveen.beniwal | last post by:
hi all i am having the following line of code in my mak file. !IF "$(CFG)" == "" CFG=DesktopCommon - Win32 Release !MESSAGE No configuration specified. Defaulting to DesktopCommon -...
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...
6
by: Pixel.to.life | last post by:
So I have this perfectly fine and running app, that uses managed C++ forms. Problem#1: I pass a Bitmap reference to a class, hoping to modify it in one of the class's methods, so it...
6
by: muby | last post by:
Hi everybody :) I'm modifying a C++ code in VC++ 2005 my code snippet void BandwidthAllocationScheduler::insert( Message* msg, BOOL* QueueIsFull,
4
by: srinathvs | last post by:
Hi, I have an access db that I am trying to query from a vb6 program. I've the following code: Dim sSQLQuery As String sSQLQuery = "SELECT * FROM TblData WHERE ID = " & Chr(39) & ID &...
2
shashahayes
by: shashahayes | last post by:
I am getting an error on this line, does anyone have any suggestions? here is the error here is line 25 if area > 750 then charge = 200 1>Furniture.cpp
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
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
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...

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.