The following code was used to display the contents of a DB. When a user entered in a value in the form, the results.php page (see below) would basically display the results.
Here is the code for the form:
<html>
<head>
<title>Product Search</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<STYLE>A {
TEXT-DECORATION: none
}
A:hover {
COLOR: #ff3333; TEXT-DECORATION: underline
}
</STYLE><LINK
href="styles.css" type=text/css rel=stylesheet>
<body ONLOAD="document.price_search.searchterm.focus();" bgcolor="#ececec" leftmargin=0 topmargin=0>
<table width="375" border="1" align="left" cellpadding="2" cellspacing="0" bordercolor="#999999">
<tr>
<td width="343" height="20" bgcolor="#CCCCCC"><font color="#FFFFFF"><font color="#FFFFFF"><img src="images/product_search.gif" width="143" height="25"></font></font></td>
</tr>
<tr>
<td height="85" bgcolor="#FFFFFF">
<table width="100%" height="100%" border="0" cellpadding="2" cellspacing="0">
<tr>
<td><font color="#FFFFFF"><font color="#FFFFFF"><strong></strong></font></font>
<form name="price_search"action="results.php" method="post">
<font size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>
<input name="searchtype" type="hidden" value="prodnumber">
<!-- Use the following code to add more search functionality
<select name="searchtype" size="1" class="submit">
<option value="prodnumber">Product Number
</select>-->
<br>
<br>
Enter Product Number:<br>
<input type="text" getFocus="1"class="submit" name="searchterm" >
</font><font color="#FFFFFF"><font color="#FFFFFF"><font color="#333333" size="1" face="Verdana, Arial, Helvetica, sans-serif"><em>(I.E.
4014-11 or 4014)</em></font></font></font><br>
<br><input name="submit" type="submit" class="submit" value="Search" tabindex="1" align="absmiddle">
</form>
<font color="#FFFFFF"><font color="#333333"> </font> </font></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
Here is the code for the results: (results.php)
<?
if ( !$searchterm )
{
echo "You have not entered search details. Please go back and try again.";
exit;
}
$searchterm = addslashes($searchterm);
@ $db = mysql_connect("localhost", "dbname", "");
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("dbname");
#$query = "SELECT FROM prices WHERE ".$searchterm." like '%".searchtype."%'";
$query = "SELECT FROM prices WHERE ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p><br><i>Number of products found: ".$num_results."</i></p>";
$first_rec = "y";
$prod_comp = "";
$cnt = "1";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
$a_prod = stripslashes($row["prodnumber"]);
$a_price = stripslashes($row["price"]);
$a_um = stripslashes($row["um"]);
if ( $first_rec == 'y' )
{
$first_rec = 'n';
$prod_comp = $a_prod;
echo "<p><strong>".($cnt).". Product Number: ";
#echo "<p><strong>".($i+1).". Product Number: ";
echo $a_prod;
}
if ( $prod_comp != $a_prod )
{
$cnt = $cnt+1;
$prod_comp = $a_prod;
echo "<p><strong>".($cnt).". Product Number: ";
echo $a_prod;
}
echo "</strong><br> price: ";
echo $a_price;
echo "<i> ";
echo $a_um;
echo "</i>";
}
?>
</font><font color="#333333"> </font> </font></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><a href="javascript: history.go(-1)">Back to Search Page</a><br>
<script language="Javascript1.2">
<!--
var message = "Print this Page";
function printpage() {
window.print();
}
document.write("<form><input class=submit type=button "
+"value=\""+message+"\" onClick=\"printpage()\"></form>");
//-->
</script>
Now I'm getting an error:
Notice: Undefined variable: searchterm in C:\InetPub\wwwroot\newsite\results.php on line 20
Notice: Undefined variable: searchtype in C:\InetPub\wwwroot\newsite\results.php on line 43
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\InetPub\wwwroot\newsite\results.php on line 46
I'm guessing that something drastically has changed between 4.0.4 and 4.3.7... Any ideas what is wrong with my code?