Displaying values in select menu

I have a form select of different employees. Once you select the employee, there is a form with various checkboxes, you submit and are taken to a results page. All the checkbox information displays fine and is entered into the DB correctly, also the employee ID that is selected is coming though O.K. The only part not coming though is employee name.

MySQL tables look like this:

employees

|ID| |emp_name| |emp_id|
92 Huckleberry Fin HUCK

emp_checks

|CheckID| |EmpName| |EmpID| |Blocks| |Assessor| |AssessorID| |date_uploaded|
82 92 6,8,12,15,20 Tom Jones TOJO 2008-06-24 12:51:44

you will notice the field in the table emp_checks is blank. This is what I need to figure out how to get filled in and to display on my form results page.

here is the code in question.

the page with the select menu form


<?php
/*--------- DATABASE CONNECTION INFO--------- */
//set up table and database names
$db_name ="DBName";
$grid_name ="grid";
$employee_table="employees";
$check_table = "emp_checks";
$selectOptions = "<option value=''>Employee List</option>";
//connect to server and select database
$connection = @mysql_connect("localhost" , "UserName" , "PW" )
 or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error() );


//set the username post from login page
$Assessor=$_SESSION['Assessor'];
$AssessorID = $_SESSION['AssessorID'];
$now = date('F j, Y, g:i a', strtotime('+3 hours'));
$eid = @$_GET['emp_id'];
$name = @$_GET['emp_name'];
//gather data from employee list
$sql = "SELECT ID, emp_name, emp_id FROM $employee_table LEFT JOIN $check_table ON `ID` = `EmpID` ORDER BY ID ASC";
$result = mysql_query($sql) or die(mysql_error());

//begin building HTML table
echo '<table id="main" cellpadding="0" cellspacing="0">
   <tr id="header"><td id="info">';
if (isset($_SESSION['Assessor'])) {
echo '<p>Welcome '.$Assessor.'&nbsp;('.$AssessorID.')&nbsp;! <span class="date">Today is '.$now.'</span><br /><span class="instructions">Please choose an employee from the drop-down menu below </span></p>';}

elseif (!isset($_SESSION['Assessor'])) 
{
echo 'you are not logged in!';}

 
echo '  </tr>
  <tr>
    <td>';
	

echo '<table id="employees">
  <tr>
    <td>
	<form action="" method="get">
 <select name="emp_id" onchange="this.form.submit()" />
    ';
while(list($id,$name,$emp_id) = mysql_fetch_row($result)){
// this will select the current employee in the dropdown box

$selected = $id == $eid ? "selected" : "";

$selectOptions .= '<option value="'.$id.'" '.$selected.' />'.$name.'&nbsp;&nbsp;('.$emp_id.')</option>'."
";
$_SESSION['emp_name'] = $name;
$_SESSION['emp_id'] = $emp_id;
}
echo ".$selectOptions.";
echo '
</select>
  
</form>
</td>
</tr>

';
// Get checkboxes from emp_checks table
$ch = "SELECT Blocks FROM $check_table WHERE `EmpID` = '$eid'";
$cres = mysql_query($ch) or die(mysql_error());
$c = mysql_fetch_assoc($cres);
// put the comma seperated values in an array
$checks = explode(",", $c['Blocks']);

//Build and issue query
$sql="SELECT * from $grid_name ORDER BY Block";
$result = mysql_query($sql)or die(mysql_error());
// set the block groups
$lastblock = '';
echo '<form name="Grid" action="FU_Results.php" method="POST" />
<input type="hidden" name="emp_id" value="'.$eid.'" />

<table id="matrix" cellpadding="0" cellspacing="0">
  <tr>
    <th id="main" colspan="11"> Selling Skills Recommended Follow-up</th>
  </tr>';
while($row = mysql_fetch_assoc($result)){
// if the checkbox is in the array, check off the checkbox
$chk = in_array($row['ID'], $checks) ? "checked" : "";
  // checks to see if the block name has changed, if it has start a new row
  if($row['Block'] != $lastblock){
 echo "<tr><td id='title'>".substr($row['Block'], 1)."</td>";
  }
  echo '<td class="checkbox"><input type="checkbox" name="grid[]" value="'.$row['ID'].'" class="inactive" '.$chk.' /></td><td class="text">'.$row['Text'].'</td>
  '."
";
// set the lastblock to the current block in the loop
$lastblock = $row['Block'];
}
echo '</tr></table>
</td>
</tr>
<tr>
<td>

<div id="submit"><input type="image" src="Submit.png" name="submit" value="submit" alt="submit" class="SubmitButton" /></div>';
//end of HTML table
echo '</td>
  </tr>
</table>
</form>
</table>
  </td>
  </tr>
  </table>
';
?>

and the results page


<?php
session_start();
if(($_SESSION['login'] == 1)  && isset($_SESSION['Assessor'])){
/*--------- DATABASE CONNECTION INFO--------- */
//set up table and database names
$db_name ="DBName";
$grid_name ="grid";
$employee_table="employees";
$check_table = "emp_checks";

//connect to server and select database
$connection = @mysql_connect( "localhost" , "UserName" , "PW" )
 or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error() );
//set the username post from login page
$Assessor=$_SESSION['Assessor'];
$Assessor_ID = $_SESSION['AssessorID'];

//carry over session from select form
$name = $_SESSION['emp_name'];
$emp_id = $_SESSION['emp_id'];
//set the current date
$now = date('Y-m-d H:i:s', strtotime('+3 hours'));


// set the employee id
$emp_id = $_POST['emp_id'];

//set employee name
$name=$_POST['emp_name'];

// change the array to a comma seperated string for storage
$blocks = implode(",", $_POST['grid']);
// check if employee has an entry in the emp_checks table
$check = "SELECT CheckID FROM $check_table WHERE EmpID = '$id'";
$cres = mysql_query($check) or die(mysql_error());
$found = mysql_num_rows($cres);
  if($found > 0){
  // if an employee was found  we update the check boxes
  $update = "UPDATE $check_table SET Blocks = '$blocks' WHERE `EmpID` = '$id'";
  mysql_query($update) or die(mysql_error());
  //echo $update;
  $message = 'Assessment results for '.$name.' by '.$Assessor.',('.$Assessor_ID.') on '.$now;

  } else {
  // If employee was not found we insert the checkboxes
  
$insert = "INSERT INTO $check_table (`Assessor`,`AssessorID`,`EmpName`,`EmpID`, `Blocks`,`date_uploaded`) VALUES ('" . mysql_real_escape_string($Assessor) . "','" . mysql_real_escape_string($Assessor_ID) . "','" . mysql_real_escape_string($name) . "','" . mysql_real_escape_string($emp_id) . "', '" . mysql_real_escape_string($blocks) . "', '" . mysql_real_escape_string($now) . "')";
$rs = mysql_query($insert) or die("Problem with the query: $insert<br />" . mysql_error());
 
 
  
  
  //echo $insert;
  $message = 'Assessment results for '.$name.'  by '.$Assessor.',('.$Assessor_ID.') on '.$now;
  }
// run your code

echo '
<html>
<head></head>
<body>
<tr id="header"><th colspan="2" id="ResultsMessage">'.$message.' have been successfully submitted!</th></tr>
</body>
</html>
';

I have stripped out some of the code, but basically I am using the variable $name to display the name of the employee selected. Everything else is posting fine, but not the $name variable. Nothing displays in the message, and there is no DB entry.

Any help in the right direction is greatly appreciated. Let me know if I can provide more information to help resolve this issue.

the variable $name is what I am trying to use to display the value in the select menu.

your sql is wrong:
$sql = “SELECT ID, emp_name, emp_id FROM $employee_table LEFT JOIN $check_table ON ID = EmpID ORDER BY ID ASC”;

my sql doesn’t know which emp_name to select ( both tables have the same field )

so try this:

$sql = “SELECT a.ID, a.emp_name, b.emp_id FROM $employee_table a LEFT JOIN $check_table b ON a.ID = b.EmpID ORDER BY a.ID ASC”;

but one field is named emp_name and the other is named EmpName, so they aren’t the same(?). When I added the SQL that you posted, I get an error “Unknown column ‘b.emp_id’ in ‘field list’”

an update to this is, I am able to get the correct ID from the select menu to come through, so now I just basically need to associate that with another field in the same table and echo that information out for example.

<form>
<select>
<option value=“1”>Joe Jones</option>
</select>
</form>

this submits the correct checkbox information for employee id 1, so I just need to assocaite the relational name to that (Joe Jones) and get that to submit into my other table (emp_checks), and also echo out on a webpage.

hope this makes sense!