Hi, Im trying to do a search engine. However, im facing this errors.. Anyone can help..
Error :
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\i-document\search_admin.php on line 90
Thankz in advance.
Php Code :
<?php
//Get data
$button = isset($_GET['submit']) ? $_GET['submit'] : '';
$search = isset($_GET['search']) ? $_GET['search'] : '';
$find = isset($_GET['find']) ? $_GET['find'] : '';
if (!$button)
echo "You didn't submit a keyword.";
else
{
if (strlen($search)<=1)
echo "Search term too short";
else
{
echo "You searched for <b>$search</b><br /><br /><hr size='2'>";
//connect to database
mysql_connect("localhost","root","");
mysql_select_db("idoc");
$query = mysql_query("SELECT * FROM document WHERE $search LIKE'%$find%'");
}
$run = mysql_query($query);
$foundnum = mysql_num_rows($run);
if ($foundnum==0)
echo "No results found";
else
{
echo "$foundnum results found!<p>";
echo "<table border='1'>
<th>File Reference No.</th>
<th>File Name</th>
<th>iShare URL</th>
<th>Edit</th>
<th>Delete</th>
</tr>";
while ($rows = mysql_fetch_assoc($run))
{
echo "<tr>";
echo "<td>". $rows['file_ref'] ."</td>";
echo "<td>". $rows['file_name'] ."</td>";
echo "<td><a href=" . $rows['url'] . ">" . $rows['url'] . "</a></td>";
echo "<td><a href=edit_doc.php?id=" . $rows['id'] . ">Edit</a></td>";
echo "<td><a href=delete.php?id=" . $rows['id'] . ">Delete</a></td>";
echo "</tr>";
}
echo "</table>";
}
}
?>
Html Codes:
Htmak
<form id="form1" method="GET" action="search_admin.php">
<table>
<tr><td height="31" align="center" valign="middle" bgcolor="#990000"><span class="style1 style2">Search :</span></td></tr>
<tr><td><div align="left">Keyword :
<input name="search" type="text" id="search" size="40" /> in
<select name="field">
<option value="file_name">File Name</option>
<option value="media_type">Media Type</option>
</select>
</div>
<input type = "submit" name="submit" value="search" />
</tr>
</table>