Forum Moderators: coopster
This is what I have so far:
//the search.php where the user enters the required value
<--coding-->
<html>
<head>
<title>search</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<b>Search by : </b>
<form method="post" action="reportwrite.php">
<select name="searchList">
<option value="faultid"name="FaultID" >Faultid</option>
<option value="ReportUsername"name="ReportUsername">ReportUsername</option>
</select>
<input type="text" name="frm_search" size="30">
<input type="Submit" value="Search" align="MIDDLE">
</form>
</body>
</html>
The next page handles the value stored in the form sends it to the database and outputs the results. The current problem that I'm having is no results are being displayed.
<--coding-->
<html>
<head>
<title>report</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
require "dbvars.php"; //contains the database connection details
?>
<?
$searchList = $_POST['searchList'];
$frm_search = trim(addslashes($_POST['frm_search']));
//error message (not found message)
$XX = "No Record Found";
$query = mysql_query("SELECT * FROM Fault WHERE $searchList LIKE '%$frm_search%' ")or
die(mysql_error());
if ($row =!$query)
{
echo $frm_search;
echo "<table border=1>\n";
echo "<tr><td>FaultID</td><td>ReportUsername</td></tr>\n";
do {
printf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n", $row["FaultID"], $row["ReportUsername"]);
} while ($row = mysql_fetch_array($query));
echo "</table>\n";
}
{
print ("$XX");
}
?>
</body>
</html>
I know that the code is not very clean I just need to understand what is a miss so it can work and I can refine it later.
Thank you B-boystance
This part looks suspect to me.
if ($row =!$query)
At this point $row has not been defined and you're using it in a comparison.
Here's another way to skin the cat. Beware this is untested.
if (mysql_num_rows($query) > 0) {
echo $frm_search;
echo "<table border=1>\n";
echo "<tr><td>FaultID</td><td>ReportUsername</td></tr>\n";
while ($row = mysql_fetch_array($query)) {
printf("<tr><td>%s</td><td>%s</td></tr>\n", $row["FaultID"], $row["ReportUsername"]);
}
echo "</table>\n";
}
else
{
print ("$XX");
}