0

Hello, Im having trouble with creating page that will search a database for the values entered. I have a Search.php file that has this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Payroll and Timesheet Management Website</title>
    <link rel="stylesheet" type="text/css" href="styles.css"/>
  </head>
  <body>
  <?php writeHeader(); ?>
		<p>
	<span class="pageheader">Search for an employee:</span>
        <br />
	</p>
	<form action ="search_results.php" method="post"> 

	<div class="left_side">
		Search:<br/>
		Query:<br/>
	</div>
	<div class="middle_cont">
		<select name="searchType" id="type">
			<option name="EmployeeFName" value="EmployeeFName">Employee Name</option>
			<option name="EmployeeID" value="EmployeeID">Employee ID</option>
			<option name="EmployeeDepartment" value="EmployeeDepartment">Department</option>
			<option name="EmployeeTeam" value="EmployeeTeam">Team</option>
			<option name="ManagerID" value="ManagerID">Manager</option>
		</select>
		<br/>
		<input type="text" name="query" id="query" size="25"/><br/>
	</div>
	<p>
	<br/>
		<input type="submit" value="Search for Employee" class="button" />
	</p>
	</form>

	
  </body>
</html>

and the SearchResult.php that will actually show the results as

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Payroll and Timesheet Management Website</title>
    <link rel="stylesheet" type="text/css" href="styles.css"/>
  </head>
  <body>
	<?php writeHeader(); ?>
	<p>
	<span class="pageheader">Search Results</span><br/>
	<?php
	if(empty($_POST['query']))
	{
	exit('Please Fill in What you want to Search. Click <a href=\"search.php\">here</a> to go back.</p>');
	}
	else
	{
	echo"<i>Your search for {$_POST['query']} had the following results:</i>";
	checkLogin();
	sqlConnect();
	mysql_select_db("titans", $con);
	$XX = "No Record Found";
	$method=$_POST['searchType'];
	$search=$_POST['query'];
	$query = mysql_query("SELECT * FROM Employee WHERE $method = '$search'");
	$result = mysql_query($query);
	
	while ($row = mysql_fetch_array($query))
	{
		$variable1=$row["0"];
		$variable2=$row["1"];
		$variable2=$row["2"];
		$variable3=$row["3"];
		$variable4=$row["4"];
                $variable5=$row["5"];
print (" $variable1, $variable2, $variable3,$variable4",$variable3);
}

//below this is the function for no record!!
if (!$variable1)
{
print ("$XX");
}
//end
	}
	?>

I have tried for a week now, and this project is due friday, Can someone help? (PLEASE)

what I am trying to do is just use the values from the search.php to search the database and make the searchResult.php echo out what it found. It will search a table named Employee with values: EmployeeName, EmployeeID, ManagerID, EmployeeDepartment, and EmployeeTeam. i.e if the user selects Employee ID from the menu, and types in an ID, it will search the table for that ID and then print that Employee row which has (EmployeeName, EmployeeID, ManagerID, EmployeeDepartment, and EmployeeTeam), and if they choose department then the result page will print out the Employees with in that department, and same with the Team option....Im Sure my searchResult.php is way wrong but can someone help?

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by nav33n
1

$query = mysql_query("SELECT * FROM Employee WHERE $method = '$search'");
$result = mysql_query($query);

This is wrong. Try,

$query = "SELECT * FROM Employee WHERE $method = '$search'";
	$result = mysql_query($query);
0

This is wrong. Try,

$query = "SELECT * FROM Employee WHERE $method = '$search'";
	$result = mysql_query($query);

Ok well here It is It works:

<?php
	if(empty($_POST['query']))
	{
	exit('Please Fill in What you want to Search. Click <a href=\"search.php\">here</a> to go back.</p>');
	}
	else
	{
	echo"<i>Your search for {$_POST['query']} had the following results:</i>";
	checkLogin();
	sqlConnect();
	mysql_select_db("titans", $con);
	$XX = "No Record Found";
	$method=$_POST['searchType'];
	$search=$_POST['query'];
	$query = mysql_query("SELECT * FROM Employee WHERE $method = $search");
	$result = mysql_query($query);
	$num=mysql_numrows($result); 
	$i=0;
	echo"<table class='full'>";
	echo"<th></th><th>ID</th><th>Employee Name</th><th>Title</th><th>Team</th><th>Department</th></tr>";
	$space=' ';	
	while ($row = mysql_fetch_array($query))
	{
		$variable1=$row["EmployeeFName"];
		$variable2=$row["EmployeeLName"];
		$variable3=$row["EmployeeID"];
		$variable4=$row["EmployeeDepart"];
		$variable5=$row["EmployeeTeam"];
		$variable6=$row["ManagerID"];
		$variable7=$row["EmployeeTitle"]; 
print ("this is for $variable1, $variable6, $variable2, $variable3, $variable4.");

echo"<tr><td class='view'><form action='employee.html' method='post'><div><input type='submit' value='View' class='button' /></div></td><td name='userID' class='id'>{$variable3}</td></form><td name='userName' class='record'>{$variable1}{$space}{$variable2}  </td><td name='userTitle' class='record'>{$variable7}</td><td name='userTeam' class='record'>{$variable5}</td><td name='userDept' class='record'>{$variable4}</td></tr>";
}

However; When I select EmployeeName form the menu and type in a Name in the search.php page it returns nothing in the searchResult.php Even tho I have that EmployeeName in my table, The same is with Title, Department and Team. It only works with columns that have integers in them. Can someone show me how to do it? Ie. I select "Employee Name" in The menu and type in JOHN (or john) which I have in the table, the searchResult.php page returns "No Record Found". Same with Team or Department. HELP

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.