I have a page that searches a database by a repairman's name and by a
date range. It pulls info by the repairman's name but pulls all info in
the database regardless of the date. Below is the code of the two
pages. What am I missing?
This page calls the script datersearch.php
************
searchrdates.php
************
<html>
<head><title>Search Repair Dates</title>
</head>
<body bgcolor=#ffffff>
<center>
<P><CENTER><IMG SRC='images/MCLogo.jpg'
WIDTH='576' HEIGHT='87' NATURALSIZEFLAG='0'
ALIGN='BOTTOM'></CENTER></P>
<font face="Tahoma" size="3"><i><b>202 Harper Ave. NW Lenoir, NC
28645</b></i></font>
<br>
<br>
<br>
<br>
<input type="button" style="font-style:tahoma; font-size:10px;
font-weight:bold; color:white; background-color:#0000FF;
height:20px;"onclick="location.href="displayupdate .php'" value="Update
Repair Entry">
<input type="button" style="font-style:tahoma; font-size:10px;
font-weight:bold; color:white; background-color:#0000FF;
height:20px;"onclick="location.href="displayupdate .php'" value="Display
Repair Entries">
<input type="button" style="font-style:tahoma; font-size:10px;
font-weight:bold; color:white; background-color:#0000FF;
height:20px;"onclick="location.href="searchrdates. php'" value="Search
Repair Entries">
<input type="button" style="font-style:tahoma; font-size:10px;
font-weight:bold; color:white; background-color:#0000FF;
height:20px;"onclick="location.href="index.php'" value="Home">
<br>
<br>
<br>
<font face="Tahoma" size=3><b>Search Repairs By Date</b></font>
<br>
<i>(Example of Date Format: Jun 1, 2005)</i>
<table>
<tr>
<form method="post" action="datersearch.php">
<td>From This Date:</td>
<td><input name="from" type="text" id="from"></td>
<td></td></tr>
<tr><td>Back To This Date:</td>
<td><input name="to" type="text" id="to"></td>
<td></td></tr>
<tr><td>For Repairman:</td>
<td><SELECT NAME="name">
<OPTION VALUE="Lisa Creamer" SELECTED>Lisa Creamer
<OPTION VALUE="Jim Stone">Jim Stone
<OPTION VALUE="Rick Stapleton">Rick Stapleton
<OPTION VALUE="Eddie Little">Eddie Little
<OPTION VALUE="Brandon Miller">Brandon Miller
</td>
<td></td></tr>
<td></td>
<td><input type="submit" style="font-style:tahoma; font-size:10px;
font-weight:bold; color:white; background-color:#0000FF; height:22px;"
value="Search">
</td><td></td></tr>
</table>
<?
include("footer.php";
?>
</form>
</body>
</center>
</html>
***************
datersearch.php
***************
<?php
$search = $_REQUEST['name'];
$from = $_REQUEST['from'];
$to = $_REQUEST['to];
if($search) // perform search only if a string was entered.
{
mysql_connect("192.168.1.8","root","passwordhere") ;
mysql_select_db("repair"); //database name
$srch = "%".$search."%";
$query = "SELECT * FROM repair WHERE repairman LIKE '$srch' AND
daterepaired BETWEEN '$from' AND '$to'";
$total = "SELECT SUM(price) as price FROM repair WHERE repairman LIKE
'$srch' AND daterepaired BETWEEN '$from' AND '$to'";
$result = mysql_db_query("repair", $query) or die("MySQL error
#".mysql_errno().":".mysql_error());
$addtotal = mysql_db_query("repair", $total) or die("MySQL error
#".mysql_errno().":".mysql_error());
if ($result)
{
echo "<font face='Tahoma' size=2><P><CENTER><IMG SRC='images/MCLogo.jpg
WIDTH='576' HEIGHT='87' NATURALSIZEFLAG='0'
ALIGN='BOTTOM'></CENTER></P></font>
<br>
<br>
echo "<table border=0 cellpadding=3 cellspacing=5>
<tr bgcolor=#104E8B>
<td width=10><font size=2 color=#FFFF00
face=tahomo><b>ID</b></font></td>
<td width=10><font size=2 color=#FFFF00 face=tahomo><b>DATE
REPAIRED</b></font></td>
<td width=12><font size=2 color=#FFFF00 face=tahomo><b>TICKET
NUMBER</b></font></td>
<td width=10><font size=2 color=#FFFF00
face=tahomo><b>REPAIRMAN</b></font></td>
<td width=10><font size=2 color=#FFFF00 face=tahomo><b>DATE
RECEIVED</b></font></td>
<td width=15><font size=2 color=#FFFF00
face=tahomo><b>LOCATION</b></font></td>
<td width=10><font size=2 color=#FFFF00
face=tahomo><b>PRICE</b></font></td>
<td width=10><font size=2 color=#FFFF00
face=tahomo><b>M&R</b></font></td>
</tr>;
while ($r = mysql_fetch_array($result)) {//Begin while
$id = $r["id"];
$daterepaired = $r["daterepaired"];
$ticketnumber = $r["ticketnumber"];
$repairman = $r["repairman"];
$datereceived = $r["datereceived"];
$location = $r["location"];
$price = $r["price"];
$mr = $r["mr"];
echo "<tr bgcolor-669966>
<td>$id</td>
<td>$daterepaired</td>
<td>$ticketnumber</td>
<td>$repairman</td>
<td>$datereceived</td>
<td>$location</td>
<td>$price</td>
<td>$mr</td>
</tr>";
} // end while
echo "</table>";
}
while ($t = mysql_fetch_array($addtotal)) {// Begin while
$price = $t["price"];
$commission = $price*.06;
echo "<table><tr>
<td><font size=4>Repairs for $repairman for the date range $to to $from
are: <b>$ $price</b></font></td></tr>
<tr><td><font size=4>and commission is: <b>$
$commission</b></font></td></tr></table>";
}
} else{
echo "Search field is empty. <br> Go back and enter something to search
by or click Display to view all repairs.";
}
?>
<?
include("footer.php";
?>
Ok, that's my code. It pulls info by the repairman but pulls all dates
no matter what dates are in the "to" and "from". I'm new at this and am
probably doing something stupid. Thanks in advance for your help.
Greg