Hi, All. In this script, I dynamically create a drop-down box that contains a list of department employees. An administrator can select one of those employees, click 'Submit', and proceed to a page that brings up their information for editing.
Herein lies the problem: Once an employee is selected, the value will be passed to the update page, which searches a database for a record match. If the employee exists, their profile will be displayed. What will be the SQL syntax to tell the database, "Look for the value I passed from the drop-down box!!" ???? I'm a lil confused here...
The code which dynamically generates the drop-down box is as follows:
<?php
$conn = @mysql_connect("localhost","michael","pass")
or die("Could not connect to MySQL!" .mysql_error());
$rs = @mysql_select_db("county_directory",$conn)
or die("Could not select database!" .mysql_error());
// Department is a session variable
$sql = "(SELECT id,f_name,l_name from employee_info where dept='$department' )";
$rs = mysql_query($sql,$conn)
or die("Could not execute query!" .mysql_error());
while ($row= mysql_fetch_array($rs))
{
$id = $row['id'];
$f_name = $row['f_name'];
$l_name = $row['l_name'];
$options .= "<option value=\'$id\'>".$f_name." ".$l_name;
}
And then I dynamically generate a form
<form action='generate_profile.php' method='post' name='form1'>
<SELECT name = 'choice'>
<OPTION value = '0'>Select an Employee</OPTION>
<OPTION value = '0'>==========================</OPTION>
<?=$options?>
</SELECT>
<input type='submit' name='submit' value='Submit'>
</form>
When generate_profile.php is called from the form, I need to search the database for a matching value before I can actually post a profile to be updated...
In my table name, REGISTERED_USERS, fields are
f_name , l_name , and dept .
<?php
// Populates fields for updating
foreach($HTTP_POST_VARS as $varname => $value)
$formVars[$varname]=$value;
$db1=mysql_connect("localhost","michael","pass");
mysql_select_db("COUNTY_DIRECTORY");
$query="(SELECT * FROM EMPLOYEE_INFO WHERE f_name=\"$f_name\" AND l_name=\"$l_name\" )";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$formVars = array();
$formVars["id"]=$row["id"];
$formVars["f_name"]=$row["f_name"];
$formVars["l_name"]=$row["l_name"];
$formVars["dept"]=$row["dept"];
$formVars["title"]=$row["title"];
$formVars["phone"]=$row["phone"];
$formVars["ext"]=$row["ext"];
$formVars["fax"]=$row["fax"];
$formVars["email"]=$row["email"];
mysql_close($db1);
?>
After the employee information is extracted from the database, it gets formatted into a table, and all fields are structured like this:
<b>First Name:</b>
<td><input type="text" name="f_name"
value="<? echo $formVars["f_name"]; ?>" size=50></td>
It's not so important how I echo the profile to be edited, but my question is, how do I search my database for the employee based on the value that I sent from the drop-down box??
It's a long post, but I appreciate any and all ideas. TIA, Mike