Hello,
I have been trying to figure out how to return a message to the user if they put a value in the search box and that item (word) is not in my database.
I have been able to return a message when they do not put anything in the search box, but not when the word is not in my database.
You guys have been a big help so far... thanks 🙂
// Make a MySQL Connection
mysql_connect("*****", "*****", "*****") or die(mysql_error());
mysql_select_db("*****") or die(mysql_error());
$id = "%".$_GET["search"]."%";
$sid = $_GET["search"];
// Retrieve all the data from the "dampener" table
$result = mysql_query("SELECT * FROM dampener WHERE Press_Model Like '$id'")
or die(mysql_error());
if(""($result)) //<----- HERE IS MY PROBLEM I THINK
{
echo'<p><a href="http://www.myfiberweb.com/press_sizing_chart.html" style="text-decoration: none"><img src="http://www.mywebsite.com/images/back-icon.jpg" BORDER=0></a></p>';
echo'<p><font size=\"3\">We are sorry, but we do not show that press model in our database. <br> Please check your spelling and try again. </font><img src="http://www.mywebsite.com/images/smiley.gif"></p>';
exit();
}
if(empty($sid))
{
echo'<p><a href="http://www.mywebsite.com/press_sizing_chart.html" style="text-decoration: none"><img src="http://www.mywebsite.com/images/back-icon.jpg" BORDER=0></a></p>';
echo'<p><font size=\"3\">Oooops! You forgot to enter something in the search box, even I do this once in awhile. </font><img src="http://www.mywebsite.com/images/smiley.gif"></p>';
exit();
}
echo'<p><a href="http://www.mywebsite.com/press_sizing_chart.html" style="text-decoration: none"><img src="http://www.mywebsite.com/images/back-icon.jpg" BORDER=0></a></p>';
$color1 = "#40af49"; // green
$color2 = "#c3e0ae"; // light green
echo "<table border='1'>
<tr align=center bgcolor=".$color1.">
<th><font face=\"Tahoma\" size=\"2\"><b>Press Model</b></font></th>
<th><font face=\"Tahoma\" size=\"2\"><b>Roller Diameter</b></font></th>
<th><font face=\"Tahoma\" size=\"2\"><b>Red 1 Size Form</b></font></th>
<th><font face=\"Tahoma\" size=\"2\"><b>Red 1 Ductor</b></font></th>
<th<font face=\"Tahoma\" size=\"2\"><b>Red 1 Cut Form</b></font></th>
<th><font face=\"Tahoma\" size=\"2\"><b>Red 1 Cut Ductor</b></font></th>
<th><font face=\"Tahoma\" size=\"2\"><b>Red 1 Set</b></font></th>
<th><font face=\"Tahoma\" size=\"2\"><b>Hyton Press</b></font></th>
<th><font face=\"Tahoma\" size=\"2\"><b>Hyton Cut Form</b></font></th>
<th><font face=\"Tahoma\" size=\"2\"><b>Hyton Cut Ductor</b></font></th>
<th><font face=\"Tahoma\" size=\"2\"><b>Hyton Cut </b></font>Set</b></font></th>
<th><font face=\"Tahoma\" size=\"2\"><b>Red Runner</th>
<th><font face=\"Tahoma\" size=\"2\"><b>Classic Loop Form</b></font></th>
<th><font face=\"Tahoma\" size=\"2\"><b>Classic Loop Ductor</b></font></th>
</tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "
<tr align=center bgcolor=".$color2.">
<td><font face=\"Tahoma\" size=\"2\">$row[Press_Model]</font></td>
<td><font face=\"Tahoma\" size=\"2\">$row[Roller_Diameter]</font></td>
<td><font face=\"Tahoma\" size=\"2\">$row[Red_1_Size_Form]</font></td>
<td><font face=\"Tahoma\" size=\"2\">$row[Red_1_Ductor]</font></td>
<td><font face=\"Tahoma\" size=\"2\">$row[Red_1_Cut_Form]</font></td>
<td><font face=\"Tahoma\" size=\"2\">$row[Red_1_Cut_Ductor]</font></td>
<td><font face=\"Tahoma\" size=\"2\">$row[Red_1_Set]</font></td>
<td><font face=\"Tahoma\" size=\"2\">$row[Hyton_Press]</font></td>
<td><font face=\"Tahoma\" size=\"2\">$row[Hyton_Cut_Form]</font></td>
<td><font face=\"Tahoma\" size=\"2\">$row[Hyton_Cut_Ductor]</font></td>
<td><font face=\"Tahoma\" size=\"2\">$row[Hyton_Cut_Set]</font></td>
<td><font face=\"Tahoma\" size=\"2\">$row[Red_Runner]</font></td>
<td><font face=\"Tahoma\" size=\"2\">$row[Classic_Loop_Form]</font></td>
<td><font face=\"Tahoma\" size=\"2\">$row[Classic_Loop_Ductor]</font></td>
</tr>";
}
echo "</table>";
{
if ($result = 0)
echo "Sorry, no records were found!";
}