I am dynamically populating a drop-down selection box, which holds names of employees. A department administrator will select an employee to update, and click submit. Another page, generate_profile.php , will search for that employee in the database, and display their profile information in editing fields...
Herein STILL lies the problem, which I've been steadily working with: The menu gathers the correct types of employees, I can select one, and click Submit. When generate_profile.php is called, it is not grabbing the information for the employee (from the database) to be edited...
On the page that is generating the drop-down menu, my code 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;
--------------------------------------------------------------------------------
As you can see, id, f_name, and l_name are all used to generate this dynamic drop-down menu. Right below this script, I have a form, which allows the user to actually SELECT an option from that menu...
<form action='generate_profile.php' method='post' name='form1'>
<SELECT name='choice'>
<OPTION value = '0'>Select an Employee</OPTION>
<?=$options?>
</SELECT>
<input type='submit' name='submit' value='Submit'>
</form>
When generate_profile.php is called, the employee choice should be extracted from the database, and their profile should be displayed on the screen in editing boxes...Code is as follows...
<?
// Populates fields for updating
foreach($HTTP_POST_VARS as $varname => $value)
$formVars[$varname]=$value;
$db1=mysql_connect("localhost","michael","xcrunner");
mysql_select_db("COUNTY_DIRECTORY");
$result= mysql_query("SELECT * FROM EMPLOYEE_INFO WHERE id = '" . $_POST['choice'] . "' ");
$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"];
?>
--------------------------------------------------------------------------------
As the query suggests, it will look for the employee that matches 'choice', the selection previously chosen from the drop-down menu. When I format the output, I'm simply putting each item into a table row, similar to this:
<b>First Name:</b>
<input type="text" name="id"
value="
<? echo $formVars["id"]; ?>
" size=4>
The problem still is as it was before: I am not able to extract the employee profile from the database (based) on what the user has selected from the drop-down menu on the previous page...If anyone can help me, I would be very greatful.
Thank you all in advance, Mike