General_Slaye Posted October 18, 2007 Share Posted October 18, 2007 <? $pagenum = $_GET['pagenum']; $find = $_GET['find']; $field = $_GET['field']; $searching = $_GET['searching']; $search = $_GET['search']; if ($searching =="yes") { echo "<center><h2>Results</h2></center><p>"; if ($find == "") { echo "<p>You forgot to enter a search term"; exit; } mysql_connect("(removed)", "(removed)", "(removed)") or die(mysql_error()); mysql_select_db("(removed)") or die(mysql_error()); $find = strtoupper($find); $find = strip_tags($find); $find = trim($find); if (!(isset($pagenum))) { $pagenum = 1; } $data = mysql_query("SELECT * FROM movies WHERE upper($field) LIKE'%$find%' ORDER BY title ASC") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 4; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM movies WHERE upper($field) LIKE'%$find%' ORDER BY title ASC $max") or die(mysql_error()); while($results = mysql_fetch_array( $data_p )) { Print $results['image']; Print $results['link']; echo "<br>Genre: "; Print $results['genre']; echo "<br>Release Date: "; Print $results['release_date']; echo "<br><br><br><br><br><br>"; } echo "<p>"; $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } echo "<b>Searched For:</b> " .$find; } echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&find=$find&field=$field&searching=$searching&search=$search'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&find=$find&field=$field&searching=$searching&search=$search'> <-Previous</a> "; } echo " ---- "; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next&find=$find&field=$field&searching=$searching&search=$search'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&find=$find&field=$field&searching=$searching&search=$search'>Last ->></a> "; } ?> Hi The part of the code is having problems functioning, check the part below. $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } I keep on getting this 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 '-4,4' at line 1 What it is trying to do, is that when you don't find anything in my database search, it should echo out: Sorry, but we can not find an entry to match your query<br><br> I just have no clue & don't understand why an error is being detected. Any help will be greatly appreciated. Database I'm currently using from host: Mysql 3.23 Cheers Link to comment https://forums.phpfreaks.com/topic/73875-sql-syntax-error/ Share on other sites More sharing options...
fenway Posted October 19, 2007 Share Posted October 19, 2007 Echo the query. Link to comment https://forums.phpfreaks.com/topic/73875-sql-syntax-error/#findComment-373168 Share on other sites More sharing options...
Simon Moon Posted October 20, 2007 Share Posted October 20, 2007 LIKE'%$find%' Add a space there like LIKE '%$find%' That should at least fix that one. And like fenway said, echo the query, to see if maybe something went wrong with it. A good hint, you have directly values in there not in ' chars, so see if those are integer or float, otherwise the database might not like them. I usually always wrap ' around the values just in case. Link to comment https://forums.phpfreaks.com/topic/73875-sql-syntax-error/#findComment-373683 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.