Someone please help! i am writing a code for a search function and everytime i execute the code i get the following 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 'LIMIT 0,10' at line 1
i have tried to remove the line of code to see wat happens ia search result appears but with errors.
can someone please help sort this problem. [PHP]<?php
$get = $_GET['q'];
$trim = ($get);
$row_limit = 10;
if ($trim == "" ) {
echo "<p>Enter Search</p>";
exit;
}
if (!isset ($get)) {
echo "<p>Not Valid Search</p>";
exit;
}
$conn = mysql_connect ("localhost","r oot","")
or die (mysql_error ());
mysql_select_db ("noble",$co nn) or die (mysql_error()) ;
$search = "SELECT *
FROM Clothes
WHERE Clothes_Brand LIKE \"%$trim%\"
ORDER BY Clothes_Brand";
$search_res = mysql_query($se arch);
if (mysql_num_rows ($search_res) == 0 ) {
echo "<h1>Search Result</>";
echo "<p>Sorry, your search: "" .$trim. "" returned zero results</p>";
echo "<p><a href=\"Noble_Ho mepage.html\">S earch Again?</a></p>";
}
if (empty($s)){
$s=0;
}
$search_query .= "LIMIT $s,$row_limit";
$query_result = mysql_query($se arch_query) or die(mysql_error ());
echo "<p>You searched for: "" .$get. ""</p>";
echo "Results";
$count = 1 + $s;
while ($srch = mysql_fetch_arr ay($query_resul t)) {
$title = $srch ['Clothes_Brand'];
echo "$count.) $title" ;
$count++ ;
}
$current = (($s/$row_limit) + 1);
if ($s>=1) {
$previous=($s-$row_limit);
print " <a href=\"$PHP_SEL F?s=$previous&q =$get\"><< ;
Prev 10</a>  " ;
}
[/PHP]
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 'LIMIT 0,10' at line 1
i have tried to remove the line of code to see wat happens ia search result appears but with errors.
can someone please help sort this problem. [PHP]<?php
$get = $_GET['q'];
$trim = ($get);
$row_limit = 10;
if ($trim == "" ) {
echo "<p>Enter Search</p>";
exit;
}
if (!isset ($get)) {
echo "<p>Not Valid Search</p>";
exit;
}
$conn = mysql_connect ("localhost","r oot","")
or die (mysql_error ());
mysql_select_db ("noble",$co nn) or die (mysql_error()) ;
$search = "SELECT *
FROM Clothes
WHERE Clothes_Brand LIKE \"%$trim%\"
ORDER BY Clothes_Brand";
$search_res = mysql_query($se arch);
if (mysql_num_rows ($search_res) == 0 ) {
echo "<h1>Search Result</>";
echo "<p>Sorry, your search: "" .$trim. "" returned zero results</p>";
echo "<p><a href=\"Noble_Ho mepage.html\">S earch Again?</a></p>";
}
if (empty($s)){
$s=0;
}
$search_query .= "LIMIT $s,$row_limit";
$query_result = mysql_query($se arch_query) or die(mysql_error ());
echo "<p>You searched for: "" .$get. ""</p>";
echo "Results";
$count = 1 + $s;
while ($srch = mysql_fetch_arr ay($query_resul t)) {
$title = $srch ['Clothes_Brand'];
echo "$count.) $title" ;
$count++ ;
}
$current = (($s/$row_limit) + 1);
if ($s>=1) {
$previous=($s-$row_limit);
print " <a href=\"$PHP_SEL F?s=$previous&q =$get\"><< ;
Prev 10</a>  " ;
}
[/PHP]
Comment