I'm having a problem with one of my scripts. Can you please take a look at it and give any hints on what I'm doing wrong.
--------------------------
The error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/virtual/site107/fst/var/ on line 41
number of Q&A found:
--------------------------
My database is lisathomaspayne_com and the table I'm tryn to search is phpbb_qa. phpbb_qa has 4 fields: id, ltptype, question and answer. I want the script to search all of the fields.
<table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
<tr>
<td align="left" valign="middle" class="tdupcom">Subscribers Home</td>
</tr>
<tr>
<td colspan="2" align="left" valign="top" class="maincont">
<div align="right"><img src="images/ltp_bullet2.gif" alt="" width="13" height="12" border="0"> <a href="javascript:history.go(-1)">back</a></div>
<?
trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo " You've not entered search details. Please go back and try again.";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
$host = '***';
$user = '***';
$pwd = '***';
$db = 'lisathomaspayne_com';
$db_table = 'phpbb_qa';
$conn = mysql_connect($host,$user,$pwd);
if (!$conn)
{
echo "error: couldn't connect to database. Please try again later.";
exit;
}
mysql_select_db($db_table,$conn);
$query = "select * from phpbb_qa where ".$searchtype." like
'%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "number of Q&A found: ".$num_results."";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Q: ";
echo htmlspecialchars( stripslashes($row["id"]));
echo "</p>";
}
?>
</td>
</tr>
</table>
--------------------------
The error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/virtual/site107/fst/var/ on line 41
number of Q&A found:
--------------------------
My database is lisathomaspayne_com and the table I'm tryn to search is phpbb_qa. phpbb_qa has 4 fields: id, ltptype, question and answer. I want the script to search all of the fields.
<table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
<tr>
<td align="left" valign="middle" class="tdupcom">Subscribers Home</td>
</tr>
<tr>
<td colspan="2" align="left" valign="top" class="maincont">
<div align="right"><img src="images/ltp_bullet2.gif" alt="" width="13" height="12" border="0"> <a href="javascript:history.go(-1)">back</a></div>
<?
trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo " You've not entered search details. Please go back and try again.";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
$host = '***';
$user = '***';
$pwd = '***';
$db = 'lisathomaspayne_com';
$db_table = 'phpbb_qa';
$conn = mysql_connect($host,$user,$pwd);
if (!$conn)
{
echo "error: couldn't connect to database. Please try again later.";
exit;
}
mysql_select_db($db_table,$conn);
$query = "select * from phpbb_qa where ".$searchtype." like
'%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "number of Q&A found: ".$num_results."";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Q: ";
echo htmlspecialchars( stripslashes($row["id"]));
echo "</p>";
}
?>
</td>
</tr>
</table>