Jump to content

need some asstaince with table display


webguync

Recommended Posts

yea, I cannot tell, I only get a blank white page.

 

I do know that I don't get an error until I add this part

 

<?php
session_start();
if($_SESSION['login'] == 1  && isset($_SESSION['Assessor'])){
//run code

} else {
// redirect them to the login page
header('Location:AssessorLogIn.php');
}

 

Link to comment
Share on other sites

  • Replies 80
  • Created
  • Last Reply

Top Posters In This Topic

thanks, but there still must be an error somewhere

 

<?php
session_start();
if(($_SESSION['login'] == 1)  && isset($_SESSION['Assessor'])){
echo <<<STUFF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
STUFF;
/*--------- DATABASE CONNECTION INFO--------- */
//set up table and database names
$db_name ="DB_Name";
$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
$Accessor=$_POST['Assessor'];

// check to see if the submit button was pressed
if(isset($_POST['submit'])){
// set the employee id
$id = $_POST['emp_id'];
// 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;
  } else {
  // If employee was not found we insert the checkboxes
  $now = date("Y-m-d H:i:s");
  $insert = "INSERT INTO $check_table (`EmpID`, `Blocks`,`date_uploaded`) VALUES ('$id', '$blocks', '$now')";
  mysql_query($insert) or die(mysql_error());
  echo $insert;

  }
} else {
//gather data from employee list
$sql = "SELECT ID, Employee_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 '<form action="" method="get">';
echo '<table id="main">
  <tr id="header"><td>';
  if ($Accessor !=null)
{echo ("Welcome $Assessor!<br />Please choose an employee from the menu list below" );}
echo '<img src="NN-logo.png" alt="Norvo Nordisk" /></td>';
echo '  </tr>
  <tr>
    <td>';

echo '<table id="employees">
  <tr>
    <td>
    <select name="emp_id" onchange="this.form.submit()" />
    ';
while(list($id,$name,$emp_id) = mysql_fetch_row($result)){
// this will select the current employee int he dropdown box
$selected = $id == $emp_id ? "selected" : "";
    echo '<option value="'.$id.'" '.$selected.' />'.$name.' (' .$emp_id.')</option>'."\n";
}
echo '</select>
    </td>
  </tr>
</form>
</table>';
// Get checkboxes from emp_checks table
$ch = "SELECT Blocks FROM $check_table WHERE `EmpID` = '$emp_id'";
$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="'.$emp_id.'" />

<table id="matrix">
  <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><input type="checkbox" name="grid[]" value="'.$row['ID'].'" class="inactive" '.$chk.' /></td><td>'.$row['Text'].'</td>';
// set the lastblock to the current block in the loop
$lastblock = $row['Block'];
}
echo '</tr></table>
<div id="submit"><input type="image" src="Submit.png" name="submit" value="submit" alt="submit" /></div>';
//end of HTML table
echo '</td>
  </tr>
</table>
</form>';
} else {
// redirect them to the login page
header('Location:AssessorLogIn.php');
}
?>

</body>
</html>

Link to comment
Share on other sites

I needed to move on for now, so I just added this part

<?php
session_start();
if($_SESSION['login'] == 1  && isset($_SESSION['Assessor']))

 

and left off

{
code that does stuff
} else {
// redirect them to the login page
header('Location:AssessorLogIn.php');
}

 

becuase that part was somehow giving me an error.

 

I do have another issue though.

 

on my login page when they type in their name in the input field and submit, the resulting page should say welcome '[insert name here']

 

it doesn't do that though.

 

the code I am using that should produce that is

 

//set the username post from login page
$Accessor=$_POST['Assessor'];

if ($Accessor !=null)
{echo ("Welcome $Assessor!<br />Please choose an employee from the menu list below" );}

 

login script again is

 

<?php
session_start();
if(isset($_POST['Assessor'])){
$_SESSION['Assessor'] = $_POST['Assessor']; // username come from database
$_SESSION['login'] = 1; // set the login to active or 1
header('Location:index_test.php'); // change this line to the page you want them to go to
} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="index_test.php" method="post" >
<table id="login">
<tr>
<td align="center">
<table id="login2">

<tr class="input">
<td>
<label for="Name">First and Last Name:</label>
<input type="text" size="45" name="Assessor" id="accessor" />
</td>
<td><input type="image" src="Submit.png" name="submit1" value="submit" alt="submit" id="submit" /></td>

</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
?>

 

 

why doesn't this work?

Link to comment
Share on other sites

update on this, it looks like my variables are not being parsed. Here is the code

 

if (!isset($_SESSION['Assessor'])) {
echo 'Welcome $Assessor<br /> Today is $now';}

else {
echo 'you are not logged in!';}

 

prints out "Welcome $Assessor

Today is $now"

 

my variables assigment is as follows

 

$Assessor=$_SESSION['Assessor'];
$now = date("Y-m-d H:i:s");

 

apparently the session variable is working because the if echo is being printed. Why aren't my variables working though?

Link to comment
Share on other sites

you can't put variables right inside single quotes. You can in double quotes. You have to come out of the quotes if using single quotes.

if (!isset($_SESSION['Assessor'])) {
echo 'Welcome '.$Assessor.'<br /> Today is '.$now.'';}

else {
echo 'you are not logged in!';}

 

Ray

 

Link to comment
Share on other sites

thanks, Ray,

 

I finally got the session code to work without the errors (blank white page), but I cannot make it past the login screen now. The conditions to allow you to go to the assessment(2nd page) are not being met. Is there a way to debug why this is happening?

 

I will post my login code, and the code for the assessment page that is redirecting me back

 

<?php
session_start();
if(isset($_POST['Assessor'])){
$_SESSION['Assessor'] = $_POST['Assessor']; // username come from database
$_SESSION['login'] = 1; // set the login to active or 1
header('Location:index_test.php'); // change this line to the page you want them to go to
} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="index_test.php" method="post" >
<table id="login">
<tr>
<td align="center">
<table id="login2">
<tr class="input">
<td>
<label for="Name">First and Last Name:</label>
<input type="text" size="45" name="Assessor" id="accessor" />
</td>
<td><input type="image" src="Submit.png" name="submit1" value="submit" alt="submit" id="submit" /></td>

</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
?>

 


 

 


<?php
session_start();
if(($_SESSION['login'] == 1)  && isset($_SESSION['Assessor'])) {
?>

code that actually does stuff is here

<?php
} else {
// redirect them to the login page
header('Location:AssessorLogIn.php');
}
?>

 

If I didn't ope and close the php for the top and bottom, I got the parsing error, so don't know if that is causing the session code to work?

Link to comment
Share on other sites

also need to know how to set another variable. I need to add another input to the login screen named AssessorID

 

how would I add that to this

 

<?php
session_start();
if(isset($_POST['Assessor'])){
$_SESSION['Assessor'] = $_POST['Assessor']; // Post name from input field
$_SESSION['login'] = 1; // set the login to active or 1
header('Location:index_test.php'); // change this line to the page you want them to go to
} else {
?>

Link to comment
Share on other sites

actually, I didn't mean to that part. I guess that would just be

<?php
session_start();
if(isset($_POST['Assessor'])){
$_SESSION['Assessor'] = $_POST['Assessor']; // Post name from input field
$_SESSION['AssessorID'] = $_POST['AssessorID']; // Post name from input field
$_SESSION['login'] = 1; // set the login to active or 1
header('Location:index_test.php'); // change this line to the page you want them to go to
} else {
?>

 

I would then need to know how to add to

 

<?php
session_start();
if($_SESSION['login'] == 1  && isset($_SESSION['Assessor'])){

Link to comment
Share on other sites

First I think you are going to the wrong place with the form.

Might be a good idea to tell us what the page names are when posting code

change login page to this

<?php
session_start();
if(isset($_POST['Assessor'])){
$_SESSION['Assessor'] = $_POST['Assessor']; // username come from database
$_SESSION['login'] = 1; // set the login to active or 1
header('Location:index_test.php'); // change this line to the page you want them to go to
} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="" method="post" >
<table id="login">
<tr>
<td align="center">
<table id="login2">
<tr class="input">
<td>
<label for="Name">First and Last Name:</label>
<input type="text" size="45" name="Assessor" id="accessor" />
</td>
<td><input type="image" src="Submit.png" name="submit1" value="submit" alt="submit" id="submit" /></td>

</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
?>

 

Basically you want the form to submit to itself not to the index_test page. So just remove the action page and leave it blank to submit to itself.

 

Ray

Link to comment
Share on other sites

thanks , I will try that.

 

also I added another input field to my login form and to the session code at the top I now have

 

<?php
session_start();
if(isset($_POST['Assessor'])){
$_SESSION['Assessor'] = $_POST['Assessor']; // Post name from input field
$_SESSION['AssessorID'] = $_POST['AssessorID']; // Post AssessorID from input field
$_SESSION['login'] = 1; // set the login to active or 1
header('Location:index_test.php'); // change this line to the page you want them to go to
} else {
?>

 

I am not sure how to adjust this part t include the new session variable

 

<?php
session_start();
if(($_SESSION['login'] == 1)  && isset($_SESSION['Assessor']))
?>

 

 

Link to comment
Share on other sites

ok, now I login and am taken to the second page (index_test.php)

 

For some reason this piece of code

 

if (!isset($_SESSION['Assessor'])) {
echo 'Welcome '.$Assessor.' '.$AssessorID.'<br /> Today is '.$now.'';}

else {
echo 'you are not logged in!';}

 

displays 'you are not logged in', even though I just did!

 

so something is not coming through correctly with the session variables.

 

let me know if I need to repost any of the code on the index_test.php page

 

 

Link to comment
Share on other sites

By using the "!" in front of isset you actually are checking for the opposite of the function. Or should I say checking to see if it is false.

So since the value is actually set, by putting the "!" in, your statement is false in which case you display the second part of your if statement.

 

Ray

Link to comment
Share on other sites

ok, thanks I can get it to display the Assessor login name now, but it is not evaluating $Now or $AssessorID

 

the $now variable is set before hand as:

 

$now = date("Y-m-d H:i:s");

 

and the AssessorID is set on the login page as:

 

$_SESSION['AssessorID'] = $_POST['AssessorID']; // Post AssessorID from input field

 

I also have a results display page which isn't doing anything yet. The form action on my assessor page is set to this page called 'FU_Results.php', and the code is:

 

<?php
session_start();
if(($_SESSION['login'] == 1)  && isset($_SESSION['Assessor'])){

// run your code
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Novo Nordisk Selling Skills Recommended Follow-up Results page</title>
<link rel="stylesheet" href="Global.css" type="text/css" media="screen, handheld" />
</head>
<body>
<table>
<tr><th>Assessment results for $emp, submitted by $accessor</th></tr>
<tr>
<td>'.$name.'</td><td>'.$emp_id.'</td><td>'.$blocks.'</td><td></td>
</tr>
</table>
</body>
</html>
';
} else {
// redirect them to the login page
header('Location:AssessorLogIn.php');
}
?>

so basically not of my variables are being evaluated on this page. Do I need to set them all over again?

THANKS!!!

 

 

 

Link to comment
Share on other sites

If you don't store the values in a session, they will not be available from page to page. If you set $name on a previous page it is not available to the next page unless you set it as a session or pass it through the url. so even though you set values on one page you have to set them again on the next page.

 

If you want to post the code for all your pages and give me the names for each page I will look through them for you.

 

Ray

Link to comment
Share on other sites

Thanks, I would appreciate that, I feel like I am pretty close to having what I need.

 

In addition to the issue with all of the variables not displaying correctly on the index_test.php page, other issues I need to resolve are I want the information in the initial login form (Assessor, AssessorID) to post in the MySQL table emp_checks when the form is submitted. I have fields already set up for that. Ideally, I would also like to post the actual text of what is submitted instead of just the ID's, if possible. Lastly, when a submission is made, nothing is being recored for the date_uploaded, var $Now in the database.

 

let me know if I can clarify anything as far as what I am having issues with.

 

thanks again!

 

AssessorLogIn.php

 

<?php
session_start();
if(isset($_POST['Assessor'])){
$_SESSION['Assessor'] = $_POST['Assessor']; // Post name from input field
$_SESSION['login'] = 1; // set the login to active or 1
header('Location:index_test.php'); // change this line to the page you want them to go to
} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Novo Nordisk Selling Skills Recommended Follow-up</title>
<link rel="stylesheet" href="Global.css" type="text/css" media="screen, handheld" />

</head>
<body>
<form action="" method="post" >
<table id="login">
<tr>
<td align="center">
<table id="login2">
<tr class="input">
<td>
<label for="Name">First and Last Name:</label><br /><br />
<input type="text" size="45" name="Assessor" id="accessor" />
</td>
<td><img src="logo.png" alt="logo" /></td>


</tr>
<tr class="input">
<td>
<label for="ID">Assessor ID:</label><br /><br />
<input type="text" size="45" name="AssessorID" id="accessor" />
</td>
<td><input type="image" src="Submit.png" name="submit1" value="submit" alt="submit" id="submit" /></td>

</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
?>

 

index_test.php

 


<?php
session_start();
if(($_SESSION['login'] == 1)  && isset($_SESSION['Assessor'])) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> Selling Skills Recommended Follow-up</title>
<link rel="stylesheet" href="Global.css" type="text/css" media="screen, handheld" />

</head>
<body>
<?php
/*--------- 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'];

// check to see if the submit button was pressed
if(isset($_POST['submit'])){
// set the employee id
$id = $_POST['emp_id'];
// 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;
  } else {
  // If employee was not found we insert the checkboxes
  $now = date("Y-m-d H:i:s");
  $insert = "INSERT INTO $check_table (`EmpID`, `Blocks`,`date_uploaded`) VALUES ('$id', '$blocks', '$now')";
  mysql_query($insert) or die(mysql_error());
  echo $insert;

  }
} else {
//gather data from employee list
$sql = "SELECT ID, Employee_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 '<form action="" method="get">';
echo '<table id="main">
  <tr id="header"><td colspan="2">';
if (isset($_SESSION['Assessor'])) {
echo 'Welcome '.$Assessor.' '.$AssessorID.'<br /> Today is '.$now.'';}

elseif (!isset($_SESSION['Assessor'])) 
{
echo 'you are not logged in!';}
echo '</td>';
echo '<td><img src="novo-logo.png" alt="Novo Nordisk" /></td>';
echo '  </tr>
  <tr>
    <td>';

echo '<table id="employees">
  <tr>
    <td>
    <select name="emp_id" onchange="this.form.submit()" />
    ';
while(list($id,$name,$emp_id) = mysql_fetch_row($result)){
// this will select the current employee int he dropdown box
$selected = $id == $emp_id ? "selected" : "";
    echo '<option value="'.$id.'" '.$selected.' />'.$name.' (' .$emp_id.')</option>'."\n";
}
echo '</select>
    </td>
  </tr>
</form>
</table>';
// Get checkboxes from emp_checks table
$ch = "SELECT Blocks FROM $check_table WHERE `EmpID` = '$emp_id'";
$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="'.$emp_id.'" />

<table id="matrix">
  <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>'.$row['Text'].'</td>'."\n";
// set the lastblock to the current block in the loop
$lastblock = $row['Block'];
}
echo '</tr></table>
<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>';
}
?>
</body>
</html>
<?
} else {
// redirect them to the login page
header('Location:AssessorLogIn.php');
}
?>

 

FU_Results.php

 

<?php
session_start();
if(($_SESSION['login'] == 1)  && isset($_SESSION['Assessor'])){

// run your code
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Novo Nordisk Selling Skills Recommended Follow-up Results page</title>
<link rel="stylesheet" href="Global.css" type="text/css" media="screen, handheld" />
</head>
<body>
<table>
<tr><th>Assessment results for '.$emp.', submitted by '.$Assessor.','.$Assessor_ID.'</th></tr>
<tr>
<td>'.$name.'</td><td>'.$emp_id.'</td><td>'.$blocks.'</td><td>'.$Text.'</td>
</tr>
</table>
</body>
</html>
';
} else {
// redirect them to the login page
header('Location:AssessorLogIn.php');
}
?>

Link to comment
Share on other sites

OK made the changes. I didn't add the inserts for the assessor and assessor ID you can do that in th FU_Results page for both the UPDATE query and the INSERT query

 

AssessorLogIn.php

<?php
session_start();
if(isset($_POST['Assessor'])){
$_SESSION['Assessor'] = $_POST['Assessor']; // Post name from input field
$_SESSION['AssessorID'] = $_POST['AssessorID'];
$_SESSION['login'] = 1; // set the login to active or 1
header('Location:index_test.php'); // change this line to the page you want them to go to
} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Novo Nordisk Selling Skills Recommended Follow-up</title>
<link rel="stylesheet" href="Global.css" type="text/css" media="screen, handheld" />

</head>
<body>
<form action="" method="post" >
<table id="login">
<tr>
<td align="center">
<table id="login2">
<tr class="input">
<td>
<label for="Name">First and Last Name:</label><br /><br />
<input type="text" size="45" name="Assessor" id="accessor" />
</td>
<td><img src="logo.png" alt="logo" /></td>


</tr>
<tr class="input">
<td>
<label for="ID">Assessor ID:</label><br /><br />
<input type="text" size="45" name="AssessorID" id="accessor" />
</td>
<td><input type="image" src="Submit.png" name="submit1" value="submit" alt="submit" id="submit" /></td>

</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
?>

 

index_test.php

<?php
session_start();
if(($_SESSION['login'] == 1)  && isset($_SESSION['Assessor'])) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> Selling Skills Recommended Follow-up</title>
<link rel="stylesheet" href="Global.css" type="text/css" media="screen, handheld" />

</head>
<body>
<?php
/*--------- 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() );*/
require('../config.php');
include('../includes/mysql.php');

//set the username post from login page
$Assessor=$_SESSION['Assessor'];
$AssessorID = $_SESSION['AssessorID'];
$now = date("Y-m-d H:i:s");
$eid = @$_GET['emp_id'];

//gather data from employee list
$sql = "SELECT ID, Employee_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 '<form action="" method="get">';
echo '<table id="main">
  <tr id="header"><td colspan="2">';
if (isset($_SESSION['Assessor'])) {
echo 'Welcome '.$Assessor.' '.$AssessorID.'<br /> Today is '.$now.'';}

elseif (!isset($_SESSION['Assessor']))
{
echo 'you are not logged in!';
}
echo '</td>';
echo '<td><img src="novo-logo.png" alt="Novo Nordisk" /></td>';
echo '  </tr>
  <tr>
    <td>';

echo '<table id="employees">
  <tr>
    <td>
    <select name="emp_id" onchange="this.form.submit()" />
    ';
while(list($id,$name,$emp_id) = mysql_fetch_row($result)){
// this will select the current employee int he dropdown box
$selected = $id == $eid ? "selected" : "";
    echo '<option value="'.$id.'" '.$selected.' />'.$name.' (' .$emp_id.')</option>'."\n";
$_SESSION['emp_name'] = $name;
$_SESSION['emp_id'] = $id;
}
echo '</select>
    </td>
  </tr>
</form>
</table>';
// 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">
  <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>'.$row['Text'].'</td>'."\n";
// set the lastblock to the current block in the loop
$lastblock = $row['Block'];
}
echo '</tr></table>
<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>';
?>
</body>
</html>
<?
} else {
// redirect them to the login page
header('Location:AssessorLogIn.php');
}
?>

 

FU_Results.php

<?php
session_start();
if(($_SESSION['login'] == 1)  && isset($_SESSION['Assessor'])){
//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() );*/
require('../config.php');
include('../includes/mysql.php');
$grid_name ="grid";
$employee_table="employees";
$check_table = "emp_checks";
//set the username post from login page
$Assessor=$_SESSION['Assessor'];
$Assessor_ID = $_SESSION['AssessorID'];
$emp = $_SESSION['emp_name'];
$emp_id = $_SESSION['emp_id'];
$now = date("Y-m-d H:i:s");
// set the employee id
$id = $_POST['emp_id'];
// 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 Update results for '.$emp.', submitted by '.$Assessor.','.$Assessor_ID;

  } else {
  // If employee was not found we insert the checkboxes
  $insert = "INSERT INTO $check_table (`EmpID`, `Blocks`,`date_uploaded`) VALUES ('$id', '$blocks', '$now')";
  mysql_query($insert) or die(mysql_error());
  //echo $insert;
  $message = 'Assessment insert results for '.$emp.', submitted by '.$Assessor.','.$Assessor_ID;
  }
// run your code
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Novo Nordisk Selling Skills Recommended Follow-up Results page</title>
<link rel="stylesheet" href="Global.css" type="text/css" media="screen, handheld" />
</head>
<body>
<table>
<tr><th colspan=2>'.$message.'</th></tr>
<tr>
<td>Employee Name:'.$emp.'</td><td>Employee ID:'.$emp_id.'</td>
</tr>
</table>
<table>';
$text = str_replace(",", "', '", $blocks);
$lastblock = "";
$sql = "SELECT * FROM `grid` WHERE `ID` IN ('$text') ORDER BY `Block`";
//echo $sql;
$res = mysql_query($sql) or die(mysql_error());
while($r = mysql_fetch_assoc($res)){
  if($r['Block'] != $lastblock){
  echo '
  <tr>
    <td colspan="2">'.$r['Block'].'</td>
  </tr>';
  }
  echo '
  <tr>
    <td width="10"> </td>
    <td width="490">'.$r['Text'].'</td>
  </tr>
  ';
$lastblock = $r['Block'];
}
echo '
</table>
</body>
</html>
';
} else {
// redirect them to the login page
header('Location:AssessorLogIn.php');
}
?>

 

One of the problems we were having was we were using the $id variable in 2 places trying to get different values. I changed one of them to $eid.

 

Ray

Link to comment
Share on other sites

thanks again,

 

couple of things.

 

when I insert a new employee now into the db table employees it now is displayed twice in the select menu and with a zero instead of the employee ID

 

example:

 

should be Tom Jones (TOJO)

 

and displays as

 

Tom Jones (0)

Tom Jones(0)

 

did I need to make an adjustment in the database structure?

 

also to get the stored session variable inserted into the database for emp_checks do I just need to add here on the Results page or also in the index_test page?

 

$insert = "INSERT INTO $check_table (`EmpID`, `Blocks`,`date_uploaded`,`AssessorID`,`Assessor`) VALUES ('$id', '$blocks','$AssessorID','$Assessor', '$now')";

 

THANKS!!!

 

Link to comment
Share on other sites

one more little thing,

 

on the results page for the '.$blocks.' display it comes through as:

 

2UNCOVER NEEDS

 

which is how it is in the database. I tried this to get rid of the number before the wording

<td colspan="2">'.substr.$r['Block', 1].'</td>

 

but that seems to produce an error.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.