Hi All,
I have a select list in my HTML page as follows
Then i have a small script to get the values from the above, parse into an SQL statment and query for results
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?
I have a select list in my HTML page as follows
Code:
<select name="category[]" size="3" multiple="multiple" id="category">
<option value="Family">Family</option>
<option value="Cartoons">Cartoons</option>
<option value="Scenary">Scenary</option>
<option value="Photographs">Photographs</option>
</select>
Code:
if (isset($_POST['category'])) {
$category = $_POST['category'];
}
$categoryq ="";
for($categoryarray=0; $categoryarray < sizeof($category); $categoryarray++)
{
if($categoryarray < (sizeof($category)-1)) { $category_cond = " OR "; }
else { $category_cond = ""; }
$categoryq = $categoryq."image_category LIKE
'".$category[$categoryarray]."'$category_cond";
}
mysql_select_db($database_ImageGallart, $ImageGallart);
$query_rstImages =sprintf("SELECT * FROM images WHERE '".$categoryq."';");
$rstImages = mysql_query($query_rstImages, $ImageGallart) or die(mysql_error());
$row_rstImages = mysql_fetch_assoc($rstImages);
$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?
Comment