Hi,
I am dynamically creating a select list from a MySQL database (employeeProfile table) so that when the user selects an option and clicks PRINT, they are redirected to a page that displays the entire employee Profile.
Problem is that I can't pass the EmployeeID variable so that the next page knows which employee profile to display.
I am attempting 2 methods and neither works. Assuming either one of these is close to the correct way to do this, I don't know which one is the better method.
Method 1: Form action method
Method 2: HREF method
With the HREF method, I am passing a variable, but it is not the employeeID of the employee I select !!
Can someone help me fix this?
Also, why do I have to repeat the same query for each instance I want the dynamic select list? Is there a way around this?
<?php
session_start();
if ($_SESSION['valid_log'][0] != $_SERVER['REMOTE_ADDR'] ||
$_SESSION['valid_log'][1] != $_SESSION['User'])
{
//redirect to error page if session is invalid
echo '<META HTTP-EQUIV="Refresh" Content="1; URL=/error_access.html">';
exit();
}
$link = mysql_connect("localhost", "root", "password") or die("Could not connect. Please try again later.");
mysql_select_db("database",$link) or die("Could not select database. Please try again later.");
// Get Company ID for user logged into system
$query = "SELECT * FROM userProfiles,companyProfile WHERE userProfiles.CompanyID=companyProfile.CompanyID";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if($row) {
$CoID = $row["CompanyID"];
$id = $row["ProfileID"];
}
// Find employees profiles for Company ID
$query2 = "SELECT * FROM employeeProfile WHERE CompanyID=$CoID ORDER BY EmployeeLast,EmployeeFirst";
$result2 = mysql_query($query2);
$query3 = "SELECT * FROM employeeProfile WHERE CompanyID=$CoID ORDER BY EmployeeLast,EmployeeFirst";
$result3 = mysql_query($query3) or die("Error with query 3.");
/* ??????????????????????????????????????
Why do I have to repeat the same query for each instance I want the dynamic select list?
????????????????????????? */
// create select list with Print as the form function
echo '<FORM NAME="form1" METHOD="post" ACTION="f-A_initialnotice.php">
<SELECT name="initialnotice"> ';
while($line = mysql_fetch_array($result2))
{
$lastname = $line["EmployeeLast"];
$firstname = $line["EmployeeFirst"];
$id = $line["EmployeeID"];
echo "<OPTION VALUE='$id'>$lastname, $firstname</OPTION>";
}
echo'</SELECT>
<input type=hidden name="id" value="$id">
<INPUT class="small" TYPE="submit" NAME="print" VALUE="Print">
</FORM>';
// create select list with Print as the HREF function
?>
<SELECT NAME="terminations" SIZE="1">
<?
// Find employees profiles for Company ID
while($line = mysql_fetch_array($result3))
{
$lastname = $line["EmployeeLast"];
$firstname = $line["EmployeeFirst"];
$id = $line["EmployeeID"];
echo "<OPTION VALUE='$id'>$lastname, $firstname</OPTION>";
}
?> </SELECT> <A HREF="f-A_initialnotice.php?id=<?php echo $id ?>">PRINT</A>