473,396 Members | 1,827 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 SQL syntax

17
Hi, I seem to be having a problem inserting data into a database

Expand|Select|Wrap|Line Numbers
  1. // check to make sure fields are entered
  2.  if ($name == '' ||  $address1== '' || $address2 == '' || $town == '' || $county == '' || $postcode == '' || $info == '' || $price == '')
  3.  {
  4.  // generate error message
  5.  $error = 'ERROR: Please fill in all required fields!';
  6.  
  7.  // if either field is blank, display the form again
  8.  renderForm($name, $address1, $address2, $address1, $town, $county, $postcode, $info, $price, $error);
  9.  }
  10.  else
  11.  {
  12.  // save the data to the database
  13.  mysql_query("INSERT houses SET name='$name', address1='$address1',
  14.  address2='$address2', town='$town', county='$county', postcode='$postcode', info='$info', price='$price' WHERE id='$id'")
  15.  or die(mysql_error()); 
  16.  
  17.  // once saved, redirect back to the view page
  18.  header("Location: admin.php"); 
  19.  }
  20.  }
  21.  else
  22.  // if the form hasn't been submitted, display the form
  23.  {
  24.  renderForm('','','','','','','','','');
  25.  }
  26. ?> 
  27.  
  28.  
The error i'm getting is

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 'WHERE id=''' at line 2
Nov 26 '11 #1

✓ answered by Artnessde

As from what i see in your code (which is not escaping anything - may the good SQL Injections be with you) your $id variable is simply empty.

That's what the SQL Error tells you.

ALWAYS sanitize ANY Userinput and verifyt the where clause has valid and filled variables (as in any other usecase where you handle external user-input which is always possibly filtrated with potential exploit code)

2 1460
johny10151981
1,059 1GB
1. Read Insert Query structure again(If you read before) from the documentation.
2. read about sql injection from wiki
3. read about mysq_real_escape_string from php.net
Nov 26 '11 #2
As from what i see in your code (which is not escaping anything - may the good SQL Injections be with you) your $id variable is simply empty.

That's what the SQL Error tells you.

ALWAYS sanitize ANY Userinput and verifyt the where clause has valid and filled variables (as in any other usecase where you handle external user-input which is always possibly filtrated with potential exploit code)
Nov 26 '11 #3

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

Similar topics

3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
8
by: Wescotte | last post by:
The error message Parse error: syntax error, unexpected $end in FILE on line X is one I run into frequently and I know the cause is I missed an ending quote. Is there an easy way to determine...
36
by: rhys | last post by:
My Gurus and Angels -- Please pardon this old-school programmer, only recently enlightened to open-source, having been trapped in the convenience of proprietary lingos for way too long. My...
3
by: SilvaZodiac | last post by:
Hi everyone, I'm still rather new to PHP code, and I have a syntax error. I've tried several different solutions, but it won't fix. It seems to suggest that I need a new bracket somewhere in the...
3
paulrajj
by: paulrajj | last post by:
hi to all, i am getting syntax error on my code.. Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in D:\xampp\htdocs\Dummy\paulraj\matrim\exam.php on line 62 ...
10
by: benicio | last post by:
Parse error: syntax error, unexpected T_STRING, expecting '(' in C:\wamp\www\study_group\includes\functions.php on line 19 I got this error and this syntax is from 8 to 19th line. <?php ...
3
by: brkseven | last post by:
Looking for help with this Contact Form. The error is on line 1, but that' doesn't mean a lot, I think. In fact, a php syntax check passed it, but I was hoping for an easy syntax error, it looks...
3
by: CYNTHIA CUTRER | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> ...
2
by: Vicki Hendra | last post by:
Hi I am new to php fullstop I and colleagues have setup wordpress blogs for our local towns, giving the local businesses free advertisment. Part of the problem started when using wordpress...
5
by: Adam Pelling | last post by:
I'm getting this error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/neblncbt/public_html/forum/includes/acp/acp_board.php on line 69 Here is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...

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.