Jump to content

can someone talk a look at my codes and tell me whats wrong with it.


lukelee

Recommended Posts

this is the search function, when couldnt find anything, "Sorry, but we can not find an entry to match your query" this msg will jump out, otherwise, just show the result. my problem is whatever find or not, this msg will always show up.  can anyone help?  here is my code:

 

<?
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";

if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}

require_once('db.php');


$data = mysql_query("SELECT book_id, book_title,author,keyword FROM book WHERE book_title LIKE '%$_POST[find]%' OR author LIKE '%$_POST[find]%' OR keyword LIKE '%$_POST[find]%'");
?>
<table border='1'width='500'>
	<tr>
            <td>Book Id</td>
		<td>Book Title</td>
		<td>Author</td>
				</tr>
                    <?
while($result = mysql_fetch_array( $data ))
{
echo("<tr>");
echo("<td>$result[book_id]</td>");
echo("<td>$result[book_title]</td>");
echo("<td>$result[author]</td>");
echo("</tr>");

}
require_once('rent.php');
?>
</table>
<?
$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;
}
?>

<?php

$search = $_POST['find'];

if ($searching =="yes")
{
echo "<h2>Results</h2><p>";

if ($search == "")
{
echo "<p>You forgot to enter a search term";
exit;
}

require_once('db.php');


$data = mysql_query("SELECT book_id, book_title,author,keyword FROM book WHERE book_title LIKE '%$search%' OR author LIKE '%$search%' OR keyword LIKE '%$search%'");
?>
<table border='1'width='500'>
	<tr>
           <td>Book Id</td>
		<td>Book Title</td>
		<td>Author</td>
				</tr>
                   <?php
while($result = mysql_fetch_array( $data ))
{
echo("<tr>");
echo("<td>$result[book_id]</td>");
echo("<td>$result[book_title]</td>");
echo("<td>$result[author]</td>");
echo("</tr>");

}
require_once('rent.php');
?>
</table>
<?php
$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;
}
?>

try using this code let me know if it works

Can you echo out your SQL?

 

<?php

$sql = "SELECT book_id, book_title,author,keyword FROM book WHERE book_title LIKE '%$_POST[find]%' OR author LIKE '%$_POST[find]%' OR keyword LIKE '%$_POST[find]%'";

echo $sql;

?>

 

Also, doesn't mysql_query() need a link identifier as well:

<?php

$data = mysql_query($sql,$link);

?>

 

 

Can you echo out your SQL?

 

<?php

$sql = "SELECT book_id, book_title,author,keyword FROM book WHERE book_title LIKE '%$_POST[find]%' OR author LIKE '%$_POST[find]%' OR keyword LIKE '%$_POST[find]%'";

echo $sql;

?>

 

Also, doesn't mysql_query() need a link identifier as well:

<?php

$data = mysql_query($sql,$link);

?>

 

 

 

thanks man, i have solved it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.