Jump to content

need some asstaince with table display


webguync

Recommended Posts

 

 

if (!isset($_SESSION)) {
session_start();
}

 

this is what you are referring to?

 

how would I go about integrating with my username variable?

 

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

 

also, I would want to add some code on the assessment page that will detect if a user is logged in, and if not redirect back to the login page.

 

 

Link to comment
Share on other sites

  • Replies 80
  • Created
  • Last Reply

Top Posters In This Topic

don't need to check the session. just start each page with session_start(). it should be the first line on your pages.

 

After the user puts in his/her username and password and is authenticated you can add things like this

<?php
  $_SESSION['username'] = $r['FirstName']; // username come from database
  $_SESSION['login'] = 1; // set the login to active or 1
?>

 

Then on the pages you want to check for a login you can use

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

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

 

Ray

Link to comment
Share on other sites

thanks,

 

the username won't need to be authenticated against a database but they will have a form to enter their name and ID. Once they do that and submit from the login page, that information will need to display on the second screen. The way i had it previously was working on the default, but on the change event from the dropdown menu, the information would go away. I would also need to store the information from the login $username, $id into the emp_checks MySQL table.

Link to comment
Share on other sites

for this part:

 

<?php
  $_SESSION['username'] = $r['FirstName']; // username come from database
  $_SESSION['login'] = 1; // set the login to active or 1
?>

 

did that need to go at the beginning of the code for the login page or the second page after they enter the login info. and submit?

 

right now I am posting the results as such

 

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

 

and

 

<td> Welcome $Accessor
</td>

 

would this need to be done differnently using session variables?

 

Link to comment
Share on other sites

the SESSION variables would usually be set after the person has had some kind of confirmation who they are.

 

Here is a script I use for loging in

<?php
session_start();
if(isset($_POST['submit'])){
$username = $_POST['user'];
$password = $_POST['password'];

$sql = "SELECT `FirstName`, `accessrights`, `Initials` FROM `employees` WHERE `userid` = '$username' AND `password` = '$password' AND active = '1'";
$res = mysql_query($sql) or die(mysql_error());
$r = mysql_fetch_assoc($res);
$num_rows = mysql_num_rows($res);
  if($num_rows < 1){
  echo "<table width=800 height=100 align=center cellspacing=0>
    <tr>
      <td align=center>You are not logged in, or username and password incorrect.<br><a href=\"javascript:history.go(-1)\"  onMouseOver=\"self.status=document.referrer;return true\"><< LOGIN</a>
    </tr>
  </table>\n";
  exit();
  } else {
  $_SESSION['username'] = $r['FirstName'];
  $_SESSION['login'] = 1;
  $_SESSION['rights'] = explode(",", $r['accessrights']);
  $_SESSION['initials'] = $r['Initials'];
  echo "<META HTTP-EQUIV=\"Refresh\" content=\"4;url=".$phpself."\" />
  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
  <p align=center>Thank you ".$r['FirstName'].", you will now be redirected to the Customer Log.</p>\n";
  }
} else {
?>
<title>Login</title>
<form name="authenticate" method="POST" action="<?php echo $phpself; ?>?do=login">
<input type=hidden name=lrefresh value=1>
<table width=400 align=center>
  <tr>
    <td align=center>User Name <input name="user" type="text" value="" size="20"><td>
  </tr>
  <tr>
    <td align=center>Password <input name="password" type="password" value="" size="20"></td>
  </tr>
  <tr>
    <td align=center>
    <input type="submit" name="submit" value="Login">  
    <input type="reset" name="reset" value="Reset">
    </td>
  </tr>
</table>
</form>
<?php
}
?>

 

Ray

Link to comment
Share on other sites

I don't really need to confirm them though, just record the information, store in a variable and post on the subsequent pages and insert into the database along with the results of their form submission.

 

a quick question about sessions. If I use

 

session_start()

 

on my results submission page would I then be able to post the variables without transferring all of the database connection and SQL code over?

 

example:

 

<td>'.$emp_id.'</td><td>'.$assessor.'</td><td>.'$blocks.'</td>

Link to comment
Share on other sites

I was also wondering about this line of code and what it was doing.

 

$emp_id = isset($_GET['emp_id']) ? $_GET['emp_id'] : "1";

 

I added an employee code in my database in the table named 'employees' , column name is emp_id and data inserted is letters such as BLJO, but in my employee dropdown list what's gets displayed is the number beside the name which increments whenever you choose a new selection Bill Jones1, Bill Jones2 etc. What I want to display is Bill Jones (BLJO).

 

the code for the select menu is

 

echo '<option value="'.$id.'" '.$selected.' />'.$name.'' .($emp_id).'</option>'."\n";

 

thanks in advance for all of the help!

Link to comment
Share on other sites

I don't really need to confirm them though, just record the information, store in a variable and post on the subsequent pages and insert into the database along with the results of their form submission.

 

a quick question about sessions. If I use

 

session_start()

 

on my results submission page would I then be able to post the variables without transferring all of the database connection and SQL code over?

 

example:

 

<td>'.$emp_id.'</td><td>'.$assessor.'</td><td>.'$blocks.'</td>

 

Yes you can store the info in session and just echo the session values out on any page.

 

$emp_id = isset($_GET['emp_id']) ? $_GET['emp_id'] : "1";

 

This just sets the emp_id to 1 if there is no employee selected. This is basically for the first time you open the page when no employee is set. if you change the page to show info from a session then this can be taken out and you can set the $emp_id from the session.

 

We set the emp_id above and already used the variable so you would have to use a different one

you would have to add emp_id to the query

$sql = "SELECT ID, Employee_Name, emp_id FROM $employee_table LEFT JOIN $check_table ON `ID` = `EmpID` ORDER BY ID ASC";

 

then add it to the list

while(list($id,$name,$emp_code) = mysql_fetch_row($result)){

 

now you can add it

echo '<option value="'.$id.'" '.$selected.' />'.$name.'' .($emp_code).'</option>'."\n";

 

Ray

Link to comment
Share on other sites

ok, that works for listing the employee ID in the select form, thanks.

 

I am still not able to get the session variables to work properly so I must be missing something.

 

code for login page

<?php
session_start();
$_SESSION['username'] = $r['Assessor']; // username come from database
$_SESSION['login'] = 1; // set the login to active or 1
?>
<!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>
<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>

 

session code on page you are sent to after login:

 

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

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

 

 

with the code as I currently have it, I get redirected back to the login page no-matter what. I only want to get redirected back to the login page if nothing at all is entered into the input field with the name of 'Assessor'. If they enter anything at all then no redirect should occur, but what they entered should display on the second page with welcome $Assessor.

 

Link to comment
Share on other sites

change the 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:somepage.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>Selling Skills Recommended Follow-up</title>
<link rel="stylesheet" href="Global.css" type="text/css" media="screen, handheld" />

</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
}
?>

 

Once you do this the code on the second page should be fine

 

Ray

Link to comment
Share on other sites

thanks,

 

a couple of things on this I am still unclear on with sessions and session variables.

 

on the second page, if there is no login then I want the redirect to go back to the initial login page, so don't I need to post code at the top of that page to detect if there was any post to the input field?

 

also, I don't think my session_start(); code is working properly because on my results page, nothing is displaying.

 

the current code on my three pages as I have it now.

 

LOGIN PAGE

 

<?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:AssessorLogIn.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 id="LoginHeader"><td><strong>Welcome to the Novo Nordisk Follow-Up Assessment Application!</strong><br />Please enter your first and last name below and click the submit button.</td><td><img src="novo-logo.png" alt="Norvo Nordisk" /></td></tr>

<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
}
?>

 

ASSESSMENT PAGE

<?php
session_start();
?>
<!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" />

<script type="text/javascript">
   window.onload = function()
   {
      var grid = document.forms["Grid"].elements["grid[]"]; //replace formName with the name of your form

      grid.onclick = function()
      {
         var tableData = document.getElementById("ChangeMe"); //replace the tableData ID with whatever you want
         tableData.className = (tableData.className == "active") ? "inactive" : "active";
         return true; //just to be safe
      }
   }
</script>
</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" , "PassWord" )
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="logo.png" alt="logo" /></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 id="ChangeMe"><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>';
}
?>
</body>
</html>

 

AND RESULTS PAGE

 

<?php
session_start()
?>
<!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>
<?php echo '
<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>

Link to comment
Share on other sites

this line

header('Location:AssessorLogIn.php'); // change this line to the page you want them to go to

should be going to the assessment page

 

Both of the other pages should be have this in it. Just paste your code under the "//run your code" comment

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

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

that way it will redirect them back to the login page

 

this line

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

 

should be

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

 

The results page will not show any thing because you have not set the variables. you would have to set some more sessions vars or pass them through the url in order to view them.

 

Ray

 

Link to comment
Share on other sites

hmmm, I seem to be getting a syntax error with this code

 

<?php
session_start();
if($_SESSION['login'] == 1  && isset($_SESSION['Assessor'])){
// run your code
<!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>
echo "
<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');
}
?>

 

I must have something wrong in the session/redirect code.

 

also with adding the session vars to this page would it be something like this?

 

$_SESSION['$Name'] = $_POST['Name']; // username come from database

 

if that is incorrect, please post an example of setting session vars for $emp_id, $blocks, $name etc.

 

THANKS!!

Link to comment
Share on other sites

Your syntax error is because all this code:

<!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>

 

is not in some kind of echo or variable assignment or php tag closed before it or whatever you can do to make php know that that's just text and not code to be parsed.

 

As far as setting session variables:

 

is the session variable named 'name' ? or is it named something in the $Name variable? If it's the first, then take off the $ in '$Name' if it's the second then remove the ' ' around it.  The $_POST['Name'] means that you are assigning a posted variable to your session variable, so I assume that this page is a target of some form?

Link to comment
Share on other sites

thanks forget to echo out the html code :-)

 

for the results page basically, I just want to echo the results of my insert SQL from the form

 


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

 

and also include the result of

$Assessor=$_SESSION['Assessor'];

from my login page and...

 

from my select form

 

    <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>

Link to comment
Share on other sites

grrrr...I have this code in php blocks, but I am still getting a syntax error

 

<?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" />



</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
$Accessor=$_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>';
  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 id="ChangeMe"><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>';
echo '
</td>
  </tr>
</table>
</form>
</body>
</html>
';

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

 

anything obvious ?

Link to comment
Share on other sites

hmm..well i c/p'ed it into my editor and it doesn't seem to like this here:

 

echo '<table id="employees">
  <tr>
    <td>
    <select name="emp_id" onchange="this.form.submit()" />
    ';

 

It works fine if I put it all on 1 line but for some reason it don't wanna work on separate lines like that.  The quote ' don't seem to want to close, so it's throwing all your other quotes off after that. 

 

You seem to have the same style in other places as well, but those seem to work just fine. I'm kind of at a loss as to why that is...but it does seem to work if I put it on one line.

Link to comment
Share on other sites

I don't think I am doing the HEREDOC quite right...

 

<?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>
BLAH;
?>
<?php
/*--------- DATABASE CONNECTION INFO--------- */
//set up table and database names
$db_name ="Database";
$grid_name ="grid";
$employee_table="employees";
$check_table = "emp_checks";
//connect to server and select database
$connection = @mysql_connect( "localhost" , "UserName" , "Password" )
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error() );


//set the username post from login page
$Accessor=$_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>';
  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 id="ChangeMe"><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>';
echo '
</td>
  </tr>
</table>
</form>
</body>
</html>
';

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

Link to comment
Share on other sites

okay the way HEREDOC works is you can use an identifier to specify the start and the end of what you want quoted.  It pretty much has the same naming conventions as variables. In your code, you use "STUFF" as the identifier but you end it with "BLAH" you need to end it with "STUFF"

 

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;

 

The <<< tells php that the next thing you put will be the identifier.  Now here's the thing: There cannot be anything after your identifier.  No code, comments, even a space.  Same thing goes for when you are ending it. "STUFF;" needs to be on its own separate line with nothing before or after it, except for the ;

 

Link to comment
Share on other sites

I still get an error. I now have

 

<?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 ="DBNamw";
$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

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.