Jump to content

SQL Syntax error?


General_Slaye

Recommended Posts

<?

$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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.