473,387 Members | 3,820 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,387 software developers and data experts.

Sql Syntax Error when i did serveral checks

Hi All,

I have a select list in my HTML page as follows

Expand|Select|Wrap|Line Numbers
  1. <select name="category[]" size="3" multiple="multiple" id="category">
  2.         <option value="Family">Family</option>
  3.         <option value="Cartoons">Cartoons</option>
  4.         <option value="Scenary">Scenary</option>
  5.         <option value="Photographs">Photographs</option>
  6.       </select>
Then i have a small script to get the values from the above, parse into an SQL statment and query for results

Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['category'])) {
  2.   $category = $_POST['category'];
  3. }
  4.  
  5. $categoryq ="";
  6.  
  7. for($categoryarray=0; $categoryarray < sizeof($category); $categoryarray++)
  8. {
  9. if($categoryarray < (sizeof($category)-1)) { $category_cond = " OR "; }
  10. else { $category_cond = ""; }
  11. $categoryq = $categoryq."image_category LIKE
  12. '".$category[$categoryarray]."'$category_cond";
  13. }
  14.  
  15. mysql_select_db($database_ImageGallart, $ImageGallart);
  16.  
  17. $query_rstImages =sprintf("SELECT * FROM images WHERE '".$categoryq."';");
  18.  
  19. $rstImages = mysql_query($query_rstImages, $ImageGallart) or die(mysql_error());
  20.  
  21. $row_rstImages = mysql_fetch_assoc($rstImages);
  22.  
  23. $totalRows_rstImages = mysql_num_rows($rstImages);


for example if i select cartoons and familt together i get the below 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 'Family' OR image_category LIKE 'Cartoons''' at line 1

Any ideas where i gone wrong?
Dec 31 '09 #1
4 1546
code green
1,726 Expert 1GB
echo out the query then the error will be visible
Dec 31 '09 #2
thats the error that i got

SELECT * FROM images WHERE 'image_category = 'Family' OR image_category = 'Cartoons''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 'Family' OR image_category = 'Cartoons''' at line 1

i dun find anything wrong with the systax. where can i get wrong?
Jan 2 '10 #3
arhh, now i think i know where i gone wrong

the ' quotes in my sql statment. But how do i remove the single quote under this sql statement?

echo $query_rstImages =sprintf("SELECT * FROM images WHERE '".$categoryq."'");
Jan 2 '10 #4
Dormilich
8,658 Expert Mod 8TB
with mysql_real_escape_string()
Jan 2 '10 #5

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

Similar topics

8
by: Clifford W. Racz | last post by:
Does anyone know of a decent tool, preferably free, that will check and validate DTD syntax, to make sure that my DTD is correct? The only tool that I have found thus far is the IBM visual DTD...
2
by: Alicia | last post by:
Does anyone know why I am getting a "Syntax error in Create Table statement". I am using Microsoft Access SQL View to enter it. Any other problems I may run into? CREATE TABLE weeks (...
2
by: Darren Grafton via .NET 247 | last post by:
(Type your message here) -------------------------------- From: Darren Grafton I'm trying to write a webservice consuming program in vb .net toconsume a webservice from Quebec, Canada. I'm...
8
by: noob92 | last post by:
I'm using python to write a program that, when given a list of random numbers, sorts them from lowest to highest then it asks the user for a number and it checks that number's place in the sorted...
2
by: coolsmaster | last post by:
When I put my code through different inputs, one form of input results in a problem. when I enter: updatename 123456789 10 f9 the expected output is "Error: 10 is out of the range 0-4" ...
1
by: basswhizz | last post by:
Hi guys im having trouble with somethings else now can you help out thanks!! Im getting this error message Parse error: syntax error, unexpected $end Here's my code cheers!!] <?php //...
7
by: Norman Diamond | last post by:
A project depends on VC runtime from Visual Studio 2005 SP1, and DotNet Framework 2. Options are set in the setup project properties, so if these two dependencies are not already installed then...
8
by: banderson | last post by:
Hello, I have a combo box in which I want to display multiple fields by concatenating the fields together. If one of those concatenated fields is Null, then the combo box does not show anything. To...
1
by: =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?= | last post by:
On reflection, you could possibly make the app a self extracting zip file which extracts the EXE and a settings file and then starts the app, then when you app closes, it can repack the settings...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...

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.