PHP session problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have been having trouble with PHP sessions, the session variables are not able to be called through the script.

If have commented the area at the bottome where the session variable is NULL when var dump is called to check it (about 20 lines from the bottom... depending on if the text is wrapping or not)

here is the actual code
======================================================================
<?
session_start();
session_register('valid_user');
session_register('name');
/* Start A Session */

include "library/include/header.php" ;
include "library/include/database.php" ;

/* Include a header file and a database connections/functions file
*/


if ( ( !isset ( $HTTP_COOKIE_VARS["username"] ) ) && ( !isset ( $proceed ) ) && ( !isset ( $submit ) ) ) {

/* The Cookie is not set, so load the page as if it is the first time
*/



?>

<form name="login" method="post" action="<? echo $PHP_SELF; ?>">
<select name="staff">
<?
$query = " SELECT * FROM Staff ";
$result = mysql_query($query) or die( mysql_error () );

While( $row = mysql_fetch_array($result) ) {

?>
<option value="<? echo $row["0"]; ?>"><? echo $row[1]; echo " "; echo $row[2] ;?></option>
<?
}
?>
</select>
<input type="submit" name="proceed" value="proceed">
</form>
<?
}





elseif( ( !isset ( $HTTP_COOKIE_VARS["username"] ) ) && ( !isset ( $submit ) ) && ( isset ( $proceed ) ) ) {
/* The User is now attempting to register */
?>

<form name="register" method="post" action="<? echo $PHP_SELF; ?>">
<?
$staffid = $HTTP_POST_VARS["staff"];
$query = " SELECT * FROM Staff WHERE StaffId = '$staffid'";
$result = mysql_query($query) or die( mysql_error () );
$row = mysql_fetch_array($result);

session_register('valid_user');
$_SESSION["valid_user"] = $staffid;
$_SESSION['name'] = $row["1"];

?>
<table width="536" border="0">
<tr>
<td width="274">Welcome <? echo $row["1"] ; ?></td>
<td width="252">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="30">What is your National Insurance Number</td>
<td><input name="ni1" type="text" size="2" maxlength="2">
<input name="ni2" type="text" size="2" maxlength="2">
<input name="ni3" type="text" size="2" maxlength="2">
<input name="ni4" type="text" size="2" maxlength="2">
<input name="ni5" type="text" size="1" maxlength="1"></td>
</tr>
<tr>
<td>Choose a password</td>
<td><input name="pass1" type="password" size="20"></td>
</tr>
<tr>
<td>Enter it again</td>
<td><input name="pass2" type="password" size="20" maxlength="20"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="submit">
</tr>
</table>
</form>
<?
}





elseif( ( !isset ( $HTTP_COOKIE_VARS["username"] ) ) && ( isset ( $submit ) ) ) {
/* information for registration has been entered, lets check if it is valid */
$_SESSION['valid_user'] = $staffid ;
$ni = $HTTP_POST_VARS["ni1"] . $HTTP_POST_VARS["ni2"] . $HTTP_POST_VARS["ni3"] . $HTTP_POST_VARS["ni4"] . $HTTP_POST_VARS["ni5"] ;
$query = " SELECT * FROM Staff WHERE StaffId = '$staffid'";
$result = mysql_query($query) or die( mysql_error () );
$row = mysql_fetch_array($result);


/* HERE THE SESSION VARIABLE HAS NO VALUE... WHEN I CALL VARDUMP IT IS NULL */

var_dump($_SESSION["valid_user"]);
echo $ni ;
echo $staffid;
if( $ni == $row["4"]){
echo "ni check successful";
if( $pass1 != $pass2 ){

echo "Your Passwords are not the same" ;
}
else{
$query = "INSERT INTO Staff WHERE StaffId = '$staffid' password values ('$pass1')";

if($result=mysql_query($query)){
echo "your password has been set, Continue to the site";
}
}
}
}
include "library/include/footer.php" ;
?>

















_________________________________________________________________
Stay in touch with MSN Messenger http://messenger.msn.co.uk


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux