[SOLVED] Sesssions Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
sbprasad2000
Forum Newbie
Posts: 2
Joined: Sun Oct 10, 2004 12:15 pm

[SOLVED] Sesssions Problem

Post by sbprasad2000 »

Hi,

I have some problem in session management in php. I have been trying to find the problem but couldn't fix.

Code: Select all

<html>
<head>
<title></title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
.style2 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FF0000;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#BCBEC0">
<?php

	include "../include/db.inc";
	if((!isset($_POST["username"])) || (!isset($_POST["passwd"])))
	{
			include("../include/login.inc");
			exit;
	}

	//no input in the form ; return to login.html
	if(($_POST["username"]=="") || ($_POST["passwd"]==""))
	{
		include("../include/login.inc");
		echo "<center><font color="#FF0000">Must enter user ID and password fields</font></center>";
		exit;
	}

	// connection string
	$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));

	// select the DB
	$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));

	// sql query
	$sql = "SELECT * FROM student WHERE stud_id ='$_POST[username]' and pass='$_POST[passwd]'";


	// execute the sql query;
	$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));

	//retrieve the username and password from db
	//if($result&gt;0)

	if(mysql_num_rows($result)==0)
	{
		//echo " Invalid user";
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
		exit;
	}
	else
	{
		$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
		$pass = mysql_result($result,0,"pass") or die(mysql_error());
		$fname = mysql_result($result,0,"fname") or die(mysql_error());
		if($_POST&#1111;'passwd']==$pass)
		{
			session_start();
			//$first=$fname;
			//session_register('user_ID');
			//session_register('first');
			//$user_ID= $_POST&#1111;'username'];
			//$first= $fname;
			$_SESSION&#1111;'user_ID'] = $_POST&#1111;'username'];
			$_SESSION&#1111;'first'] = $fname;
			header("Location: ./account.php");
		}
		else
		{
			include("../include/login.inc");
			echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
			exit;
		}
	}
?&gt;
&lt;/body&gt;
&lt;/html&gt;
-------------------------------------------------------------------------------


Code: Select all

&lt;? 
	session_start(); 
	if (!isset($_SESSION&#1111;user_ID]))
	{
		
		//echo "No session".phpversion();
		//header("Location: ./login.php");
		//exit;
	}
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Account Information&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 10px;
	margin-top: 10px;
	margin-right: 10px;
	margin-bottom: 10px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
--&gt;
&lt;/style&gt;

&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body style="margin: 0 0 0 0"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="1" cellspacing="1"&gt;
&lt;tr valign="top"&gt;
&lt;th width="180" align="left" class="leftMain" scope="col"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;
&lt;th height="157" align="left" valign="top" scope="col"&gt;
&lt;table width="100%"  border="0" cellspacing="1" cellpadding="3"&gt;&lt;tr&gt;
&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./account.php"&gt;Home&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./viewgrades.php"&gt;Grades&lt;/a&gt;&lt;/th&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;th e problem in session management in php. I have been trying to find the problem but couldn't fix.

Code: Select all

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
.style2 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FF0000;
}
--&gt;
&lt;/style&gt;
&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body bgcolor="#BCBEC0"&gt;
&lt;?php

	include "../include/db.inc";
	if((!isset($_POST&#1111;"username"])) || (!isset($_POST&#1111;"passwd"])))
	{
			include("../include/login.inc");
			exit;
	}

	//no input in the form ; return to login.html
	if(($_POST&#1111;"username"]=="") || ($_POST&#1111;"passwd"]==""))
	{
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Must enter user ID and password fields&lt;/font&gt;&lt;/center&gt;";
		exit;
	}

	// connection string
	$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));

	// select the DB
	$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));

	// sql query
	$sql = "SELECT * FROM student WHERE stud_id ='$_POST&#1111;username]' and pass='$_POST&#1111;passwd]'";


	// execute the sql query;
	$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));

	//retrieve the username and password from db
	//if($result&gt;0)

	if(mysql_num_rows($result)==0)
	{
		//echo " Invalid user";
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
		exit;
	}
	else
	{
		$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
		$pass = mysql_result($result,0,"pass") or die(mysql_error());
		$fname = mysql_result($result,0,"fname") or die(mysql_error());
		if($_POST&#1111;'passwd']==$pass)
		{
			session_start();
			//$first=$fname;
			//session_register('user_ID');
			//session_register('first');
			//$user_ID= $_POST&#1111;'username'];
			//$first= $fname;
			$_SESSION&#1111;'user_ID'] = $_POST&#1111;'username'];
			$_SESSION&#1111;'first'] = $fname;
			header("Location: ./account.php");
		}
		else
		{
			include("../include/login.inc");
			echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
			exit;
		}
	}
?&gt;
&lt;/body&gt;
&lt;/html&gt;
-------------------------------------------------------------------------------


Code: Select all

&lt;? 
	session_start(); 
	if (!isset($_SESSION&#1111;user_ID]))
	{
		
		//echo "No session".phpversion();
		//header("Location: ./login.php");
		//exit;
	}
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Account Information&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 10px;
	margin-top: 10px;
	margin-right: 10px;
	margin-bottom: 10px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
--&gt;
&lt;/style&gt;

&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body style="margin: 0 0 0 0"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="1" cellspacing="1"&gt;
&lt;tr valign="top"&gt;
&lt;th width="180" align="left" class="leftMain" scope="col"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;
&lt;th height="157" align="left" valign="top" scope="col"&gt;
&lt;table width="100%"  border="0" cellspacing="1" cellpadding="3"&gt;&lt;tr&gt;
&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./account.php"&gt;Home&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./viewgrades.php"&gt;Grades&lt;/a&gt;&lt;/th&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./changepwd.php"&gt;Change password&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./logout.php"&gt;Logout&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt; &lt;/th&gt;&lt;/tr&gt;&lt;/table&gt; &lt;/th&gt;
&lt;th align="left" class="rightMain" scope="col"&gt;&lt;table width="100%" height="100%"  border="0" cellpadding="10" cellspacing="1"&gt;
&lt;tr&gt;&lt;th align="left" valign="top" class="forContent" scope="row"&gt;&lt;p&gt;Hi, &lt;?php echo "$_SESSION&#1111;first]"; ?&gt;&lt;/p&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
----------------------------------------------------------------------------------

the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].

I am getting the follwing error:

Code: Select all

Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61
.

But sometimes, it works..I do not understand what is the problem..

please help me..


Thanks,

Banuprasad


fe problem in session management in php. I have been trying to find the problem but couldn't fix.

Code: Select all

<html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
.style2 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FF0000;
}
--&gt;
&lt;/style&gt;
&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body bgcolor="#BCBEC0"&gt;
&lt;?php

	include "../include/db.inc";
	if((!isset($_POST&#1111;"username"])) || (!isset($_POST&#1111;"passwd"])))
	{
			include("../include/login.inc");
			exit;
	}

	//no input in the form ; return to login.html
	if(($_POST&#1111;"username"]=="") || ($_POST&#1111;"passwd"]==""))
	{
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Must enter user ID and password fields&lt;/font&gt;&lt;/center&gt;";
		exit;
	}

	// connection string
	$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));

	// select the DB
	$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));

	// sql query
	$sql = "SELECT * FROM student WHERE stud_id ='$_POST&#1111;username]' and pass='$_POST&#1111;passwd]'";


	// execute the sql query;
	$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));

	//retrieve the username and password from db
	//if($result&gt;0)

	if(mysql_num_rows($result)==0)
	{
		//echo " Invalid user";
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
		exit;
	}
	else
	{
		$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
		$pass = mysql_result($result,0,"pass") or die(mysql_error());
		$fname = mysql_result($result,0,"fname") or die(mysql_error());
		if($_POST&#1111;'passwd']==$pass)
		{
			session_start();
			//$first=$fname;
			//session_register('user_ID');
			//session_register('first');
			//$user_ID= $_POST&#1111;'username'];
			//$first= $fname;
			$_SESSION&#1111;'user_ID'] = $_POST&#1111;'username'];
			$_SESSION&#1111;'first'] = $fname;
			header("Location: ./account.php");
		}
		else
		{
			include("../include/login.inc");
			echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
			exit;
		}
	}
?&gt;
&lt;/body&gt;
&lt;/html&gt;
-------------------------------------------------------------------------------


Code: Select all

&lt;? 
	session_start(); 
	if (!isset($_SESSION&#1111;user_ID]))
	{
		
		//echo "No session".phpversion();
		//header("Location: ./login.php");
		//exit;
	}
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Account Information&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 10px;
	margin-top: 10px;
	margin-right: 10px;
	margin-bottom: 10px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
--&gt;
&lt;/style&gt;

&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body style="margin: 0 0 0 0"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="1" cellspacing="1"&gt;
&lt;tr valign="top"&gt;
&lt;th width="180" align="left" class="leftMain" scope="col"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;
&lt;th height="157" align="left" valign="top" scope="col"&gt;
&lt;table width="100%"  border="0" cellspacing="1" cellpadding="3"&gt;&lt;tr&gt;
&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./account.php"&gt;Home&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./viewgrades.php"&gt;Grades&lt;/a&gt;&lt;/th&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./changepwd.php"&gt;Change password&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./logout.php"&gt;Logout&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt; &lt;/th&gt;&lt;/tr&gt;&lt;/table&gt; &lt;/th&gt;
&lt;th align="left" class="rightMain" scope="col"&gt;&lt;table width="100%" height="100%"  border="0" cellpadding="10" cellspacing="1"&gt;
&lt;tr&gt;&lt;th align="left" valign="top" class="forContent" scope="row"&gt;&lt;p&gt;Hi, &lt;?php echo "$_SESSION&#1111;first]"; ?&gt;&lt;/p&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
----------------------------------------------------------------------------------

the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].

I am getting the follwing error:

Code: Select all

Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61
.

But sometimes, it works..I do not understand what is the problem..

please help me..


Thanks,

Banuprasad


[color=darkge problem in session management in php. I have been trying to find the problem but couldn't fix.

Code: Select all

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
.style2 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FF0000;
}
--&gt;
&lt;/style&gt;
&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body bgcolor="#BCBEC0"&gt;
&lt;?php

	include "../include/db.inc";
	if((!isset($_POST&#1111;"username"])) || (!isset($_POST&#1111;"passwd"])))
	{
			include("../include/login.inc");
			exit;
	}

	//no input in the form ; return to login.html
	if(($_POST&#1111;"username"]=="") || ($_POST&#1111;"passwd"]==""))
	{
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Must enter user ID and password fields&lt;/font&gt;&lt;/center&gt;";
		exit;
	}

	// connection string
	$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));

	// select the DB
	$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));

	// sql query
	$sql = "SELECT * FROM student WHERE stud_id ='$_POST&#1111;username]' and pass='$_POST&#1111;passwd]'";


	// execute the sql query;
	$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));

	//retrieve the username and password from db
	//if($result&gt;0)

	if(mysql_num_rows($result)==0)
	{
		//echo " Invalid user";
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
		exit;
	}
	else
	{
		$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
		$pass = mysql_result($result,0,"pass") or die(mysql_error());
		$fname = mysql_result($result,0,"fname") or die(mysql_error());
		if($_POST&#1111;'passwd']==$pass)
		{
			session_start();
			//$first=$fname;
			//session_register('user_ID');
			//session_register('first');
			//$user_ID= $_POST&#1111;'username'];
			//$first= $fname;
			$_SESSION&#1111;'user_ID'] = $_POST&#1111;'username'];
			$_SESSION&#1111;'first'] = $fname;
			header("Location: ./account.php");
		}
		else
		{
			include("../include/login.inc");
			echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
			exit;
		}
	}
?&gt;
&lt;/body&gt;
&lt;/html&gt;
-------------------------------------------------------------------------------


Code: Select all

&lt;? 
	session_start(); 
	if (!isset($_SESSION&#1111;user_ID]))
	{
		
		//echo "No session".phpversion();
		//header("Location: ./login.php");
		//exit;
	}
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Account Information&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 10px;
	margin-top: 10px;
	margin-right: 10px;
	margin-bottom: 10px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
--&gt;
&lt;/style&gt;

&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body style="margin: 0 0 0 0"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="1" cellspacing="1"&gt;
&lt;tr valign="top"&gt;
&lt;th width="180" align="left" class="leftMain" scope="col"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;
&lt;th height="157" align="left" valign="top" scope="col"&gt;
&lt;table width="100%"  border="0" cellspacing="1" cellpadding="3"&gt;&lt;tr&gt;
&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./account.php"&gt;Home&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./viewgrades.php"&gt;Grades&lt;/a&gt;&lt;/th&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./changepwd.php"&gt;Change password&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./logout.php"&gt;Logout&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt; &lt;/th&gt;&lt;/tr&gt;&lt;/table&gt; &lt;/th&gt;
&lt;th align="left" class="rightMain" scope="col"&gt;&lt;table width="100%" height="100%"  border="0" cellpadding="10" cellspacing="1"&gt;
&lt;tr&gt;&lt;th align="left" valign="top" class="forContent" scope="row"&gt;&lt;p&gt;Hi, &lt;?php echo "$_SESSION&#1111;first]"; ?&gt;&lt;/p&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
----------------------------------------------------------------------------------

the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].

I am getting the follwing error:

Code: Select all

Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61
.

But sometimes, it works..I do not understand what is the problem..

please help me..


Thanks,

Banuprasad


feyd | fixede problem in session management in php. I have been trying to find the problem but couldn't fix.

Code: Select all

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
.style2 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FF0000;
}
--&gt;
&lt;/style&gt;
&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body bgcolor="#BCBEC0"&gt;
&lt;?php

	include "../include/db.inc";
	if((!isset($_POST&#1111;"username"])) || (!isset($_POST&#1111;"passwd"])))
	{
			include("../include/login.inc");
			exit;
	}

	//no input in the form ; return to login.html
	if(($_POST&#1111;"username"]=="") || ($_POST&#1111;"passwd"]==""))
	{
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Must enter user ID and password fields&lt;/font&gt;&lt;/center&gt;";
		exit;
	}

	// connection string
	$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));

	// select the DB
	$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));

	// sql query
	$sql = "SELECT * FROM student WHERE stud_id ='$_POST&#1111;username]' and pass='$_POST&#1111;passwd]'";


	// execute the sql query;
	$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));

	//retrieve the username and password from db
	//if($result&gt;0)

	if(mysql_num_rows($result)==0)
	{
		//echo " Invalid user";
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
		exit;
	}
	else
	{
		$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
		$pass = mysql_result($result,0,"pass") or die(mysql_error());
		$fname = mysql_result($result,0,"fname") or die(mysql_error());
		if($_POST&#1111;'passwd']==$pass)
		{
			session_start();
			//$first=$fname;
			//session_register('user_ID');
			//session_register('first');
			//$user_ID= $_POST&#1111;'username'];
			//$first= $fname;
			$_SESSION&#1111;'user_ID'] = $_POST&#1111;'username'];
			$_SESSION&#1111;'first'] = $fname;
			header("Location: ./account.php");
		}
		else
		{
			include("../include/login.inc");
			echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
			exit;
		}
	}
?&gt;
&lt;/body&gt;
&lt;/html&gt;
-------------------------------------------------------------------------------


Code: Select all

&lt;? 
	session_start(); 
	if (!isset($_SESSION&#1111;user_ID]))
	{
		
		//echo "No session".phpversion();
		//header("Location: ./login.php");
		//exit;
	}
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Account Information&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 10px;
	margin-top: 10px;
	margin-right: 10px;
	margin-bottom: 10px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
--&gt;
&lt;/style&gt;

&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body style="margin: 0 0 0 0"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="1" cellspacing="1"&gt;
&lt;tr valign="top"&gt;
&lt;th width="180" align="left" class="leftMain" scope="col"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;
&lt;th height="157" align="left" valign="top" scope="col"&gt;
&lt;table width="100%"  border="0" cellspacing="1" cellpadding="3"&gt;&lt;tr&gt;
&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./account.php"&gt;Home&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./viewgrades.php"&gt;Grades&lt;/a&gt;&lt;/th&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./changepwd.php"&gt;Change password&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./logout.php"&gt;Logout&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt; &lt;/th&gt;&lt;/tr&gt;&lt;/table&gt; &lt;/th&gt;
&lt;th align="left" class="rightMain" scope="col"&gt;&lt;table width="100%" height="100%"  border="0" cellpadding="10" cellspacing="1"&gt;
&lt;tr&gt;&lt;th align="left" valign="top" class="forContent" scope="row"&gt;&lt;p&gt;Hi, &lt;?php echo "$_SESSION&#1111;first]"; ?&gt;&lt;/p&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
----------------------------------------------------------------------------------

the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].

I am getting the follwing error:

Code: Select all

Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61
.

But sometimes, it works..I do not understand what is the problem..

please help me..


Thanks,

Banuprasad


feyd[/b:a7696ae problem in session management in php. I have been trying to find the problem but couldn't fix.

Code: Select all

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
.style2 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FF0000;
}
--&gt;
&lt;/style&gt;
&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body bgcolor="#BCBEC0"&gt;
&lt;?php

	include "../include/db.inc";
	if((!isset($_POST&#1111;"username"])) || (!isset($_POST&#1111;"passwd"])))
	{
			include("../include/login.inc");
			exit;
	}

	//no input in the form ; return to login.html
	if(($_POST&#1111;"username"]=="") || ($_POST&#1111;"passwd"]==""))
	{
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Must enter user ID and password fields&lt;/font&gt;&lt;/center&gt;";
		exit;
	}

	// connection string
	$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));

	// select the DB
	$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));

	// sql query
	$sql = "SELECT * FROM student WHERE stud_id ='$_POST&#1111;username]' and pass='$_POST&#1111;passwd]'";


	// execute the sql query;
	$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));

	//retrieve the username and password from db
	//if($result&gt;0)

	if(mysql_num_rows($result)==0)
	{
		//echo " Invalid user";
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
		exit;
	}
	else
	{
		$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
		$pass = mysql_result($result,0,"pass") or die(mysql_error());
		$fname = mysql_result($result,0,"fname") or die(mysql_error());
		if($_POST&#1111;'passwd']==$pass)
		{
			session_start();
			//$first=$fname;
			//session_register('user_ID');
			//session_register('first');
			//$user_ID= $_POST&#1111;'username'];
			//$first= $fname;
			$_SESSION&#1111;'user_ID'] = $_POST&#1111;'username'];
			$_SESSION&#1111;'first'] = $fname;
			header("Location: ./account.php");
		}
		else
		{
			include("../include/login.inc");
			echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
			exit;
		}
	}
?&gt;
&lt;/body&gt;
&lt;/html&gt;
-------------------------------------------------------------------------------


Code: Select all

&lt;? 
	session_start(); 
	if (!isset($_SESSION&#1111;user_ID]))
	{
		
		//echo "No session".phpversion();
		//header("Location: ./login.php");
		//exit;
	}
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Account Information&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 10px;
	margin-top: 10px;
	margin-right: 10px;
	margin-bottom: 10px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
--&gt;
&lt;/style&gt;

&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body style="margin: 0 0 0 0"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="1" cellspacing="1"&gt;
&lt;tr valign="top"&gt;
&lt;th width="180" align="left" class="leftMain" scope="col"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;
&lt;th height="157" align="left" valign="top" scope="col"&gt;
&lt;table width="100%"  border="0" cellspacing="1" cellpadding="3"&gt;&lt;tr&gt;
&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./account.php"&gt;Home&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./viewgrades.php"&gt;Grades&lt;/a&gt;&lt;/th&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./changepwd.php"&gt;Change password&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./logout.php"&gt;Logout&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt; &lt;/th&gt;&lt;/tr&gt;&lt;/table&gt; &lt;/th&gt;
&lt;th align="left" class="rightMain" scope="col"&gt;&lt;table width="100%" height="100%"  border="0" cellpadding="10" cellspacing="1"&gt;
&lt;tr&gt;&lt;th align="left" valign="top" class="forContent" scope="row"&gt;&lt;p&gt;Hi, &lt;?php echo "$_SESSION&#1111;first]"; ?&gt;&lt;/p&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
----------------------------------------------------------------------------------

the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].

I am getting the follwing error:

Code: Select all

Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61
.

But sometimes, it works..I do not understand what is the problem..

please help me..


Thanks,

Banuprasad


feyd | fixed php code to use [b:a7 in php. I have been trying to find the problem but couldn't fix.

Code: Select all

&lt;html&gt;
&lt;head&gt;
<title></title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
.style2 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FF0000;
}
--&gt;
&lt;/style&gt;
&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body bgcolor="#BCBEC0"&gt;
&lt;?php

	include "../include/db.inc";
	if((!isset($_POST&#1111;"username"])) || (!isset($_POST&#1111;"passwd"])))
	{
			include("../include/login.inc");
			exit;
	}

	//no input in the form ; return to login.html
	if(($_POST&#1111;"username"]=="") || ($_POST&#1111;"passwd"]==""))
	{
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Must enter user ID and password fields&lt;/font&gt;&lt;/center&gt;";
		exit;
	}

	// connection string
	$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));

	// select the DB
	$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));

	// sql query
	$sql = "SELECT * FROM student WHERE stud_id ='$_POST&#1111;username]' and pass='$_POST&#1111;passwd]'";


	// execute the sql query;
	$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));

	//retrieve the username and password from db
	//if($result&gt;0)

	if(mysql_num_rows($result)==0)
	{
		//echo " Invalid user";
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
		exit;
	}
	else
	{
		$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
		$pass = mysql_result($result,0,"pass") or die(mysql_error());
		$fname = mysql_result($result,0,"fname") or die(mysql_error());
		if($_POST&#1111;'passwd']==$pass)
		{
			session_start();
			//$first=$fname;
			//session_register('user_ID');
			//session_register('first');
			//$user_ID= $_POST&#1111;'username'];
			//$first= $fname;
			$_SESSION&#1111;'user_ID'] = $_POST&#1111;'username'];
			$_SESSION&#1111;'first'] = $fname;
			header("Location: ./account.php");
		}
		else
		{
			include("../include/login.inc");
			echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
			exit;
		}
	}
?&gt;
&lt;/body&gt;
&lt;/html&gt;
-------------------------------------------------------------------------------


Code: Select all

&lt;? 
	session_start(); 
	if (!isset($_SESSION&#1111;user_ID]))
	{
		
		//echo "No session".phpversion();
		//header("Location: ./login.php");
		//exit;
	}
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Account Information&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 10px;
	margin-top: 10px;
	margin-right: 10px;
	margin-bottom: 10px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
--&gt;
&lt;/style&gt;

&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body style="margin: 0 0 0 0"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="1" cellspacing="1"&gt;
&lt;tr valign="top"&gt;
&lt;th width="180" align="left" class="leftMain" scope="col"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;
&lt;th height="157" align="left" valign="top" scope="col"&gt;
&lt;table width="100%"  border="0" cellspacing="1" cellpadding="3"&gt;&lt;tr&gt;
&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./account.php"&gt;Home&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./viewgrades.php"&gt;Grades&lt;/a&gt;&lt;/th&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./changepwd.php"&gt;Change password&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./logout.php"&gt;Logout&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt; &lt;/th&gt;&lt;/tr&gt;&lt;/table&gt; &lt;/th&gt;
&lt;th align="left" class="rightMain" scope="col"&gt;&lt;table width="100%" height="100%"  border="0" cellpadding="10" cellspacing="1"&gt;
&lt;tr&gt;&lt;th align="left" valign="top" class="forContent" scope="row"&gt;&lt;p&gt;Hi, &lt;?php echo "$_SESSION&#1111;first]"; ?&gt;&lt;/p&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
----------------------------------------------------------------------------------

the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].

I am getting the follwing error:

Code: Select all

Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61
.

But sometimes, it works..I do not understand what is the problem..

please help me..


Thanks,

Banuprasad


[colort fix.

Code: Select all

<html>
<head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
.style2 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FF0000;
}
--&gt;
&lt;/style&gt;
&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body bgcolor="#BCBEC0"&gt;
&lt;?php

	include "../include/db.inc";
	if((!isset($_POST&#1111;"username"])) || (!isset($_POST&#1111;"passwd"])))
	{
			include("../include/login.inc");
			exit;
	}

	//no input in the form ; return to login.html
	if(($_POST&#1111;"username"]=="") || ($_POST&#1111;"passwd"]==""))
	{
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Must enter user ID and password fields&lt;/font&gt;&lt;/center&gt;";
		exit;
	}

	// connection string
	$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));

	// select the DB
	$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));

	// sql query
	$sql = "SELECT * FROM student WHERE stud_id ='$_POST&#1111;username]' and pass='$_POST&#1111;passwd]'";


	// execute the sql query;
	$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));

	//retrieve the username and password from db
	//if($result&gt;0)

	if(mysql_num_rows($result)==0)
	{
		//echo " Invalid user";
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
		exit;
	}
	else
	{
		$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
		$pass = mysql_result($result,0,"pass") or die(mysql_error());
		$fname = mysql_result($result,0,"fname") or die(mysql_error());
		if($_POST&#1111;'passwd']==$pass)
		{
			session_start();
			//$first=$fname;
			//session_register('user_ID');
			//session_register('first');
			//$user_ID= $_POST&#1111;'username'];
			//$first= $fname;
			$_SESSION&#1111;'user_ID'] = $_POST&#1111;'username'];
			$_SESSION&#1111;'first'] = $fname;
			header("Location: ./account.php");
		}
		else
		{
			include("../include/login.inc");
			echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
			exit;
		}
	}
?&gt;
&lt;/body&gt;
&lt;/html&gt;
-------------------------------------------------------------------------------


Code: Select all

&lt;? 
	session_start(); 
	if (!isset($_SESSION&#1111;user_ID]))
	{
		
		//echo "No session".phpversion();
		//header("Location: ./login.php");
		//exit;
	}
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Account Information&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 10px;
	margin-top: 10px;
	margin-right: 10px;
	margin-bottom: 10px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
--&gt;
&lt;/style&gt;

&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body style="margin: 0 0 0 0"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="1" cellspacing="1"&gt;
&lt;tr valign="top"&gt;
&lt;th width="180" align="left" class="leftMain" scope="col"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;
&lt;th height="157" align="left" valign="top" scope="col"&gt;
&lt;table width="100%"  border="0" cellspacing="1" cellpadding="3"&gt;&lt;tr&gt;
&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./account.php"&gt;Home&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./viewgrades.php"&gt;Grades&lt;/a&gt;&lt;/th&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./changepwd.php"&gt;Change password&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./logout.php"&gt;Logout&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt; &lt;/th&gt;&lt;/tr&gt;&lt;/table&gt; &lt;/th&gt;
&lt;th align="left" class="rightMain" scope="col"&gt;&lt;table width="100%" height="100%"  border="0" cellpadding="10" cellspacing="1"&gt;
&lt;tr&gt;&lt;th align="left" valign="top" class="forContent" scope="row"&gt;&lt;p&gt;Hi, &lt;?php echo "$_SESSION&#1111;first]"; ?&gt;&lt;/p&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
----------------------------------------------------------------------------------

the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].

I am getting the follwing error:

Code: Select all

Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61
.

But sometimes, it works..I do not understand what is the problem..

please help me..


The problem in session management in php. I have been trying to find the problem but couldn't fix.

Code: Select all

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
.style2 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FF0000;
}
--&gt;
&lt;/style&gt;
&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body bgcolor="#BCBEC0"&gt;
&lt;?php

	include "../include/db.inc";
	if((!isset($_POST&#1111;"username"])) || (!isset($_POST&#1111;"passwd"])))
	{
			include("../include/login.inc");
			exit;
	}

	//no input in the form ; return to login.html
	if(($_POST&#1111;"username"]=="") || ($_POST&#1111;"passwd"]==""))
	{
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Must enter user ID and password fields&lt;/font&gt;&lt;/center&gt;";
		exit;
	}

	// connection string
	$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));

	// select the DB
	$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));

	// sql query
	$sql = "SELECT * FROM student WHERE stud_id ='$_POST&#1111;username]' and pass='$_POST&#1111;passwd]'";


	// execute the sql query;
	$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));

	//retrieve the username and password from db
	//if($result&gt;0)

	if(mysql_num_rows($result)==0)
	{
		//echo " Invalid user";
		include("../include/login.inc");
		echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
		exit;
	}
	else
	{
		$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
		$pass = mysql_result($result,0,"pass") or die(mysql_error());
		$fname = mysql_result($result,0,"fname") or die(mysql_error());
		if($_POST&#1111;'passwd']==$pass)
		{
			session_start();
			//$first=$fname;
			//session_register('user_ID');
			//session_register('first');
			//$user_ID= $_POST&#1111;'username'];
			//$first= $fname;
			$_SESSION&#1111;'user_ID'] = $_POST&#1111;'username'];
			$_SESSION&#1111;'first'] = $fname;
			header("Location: ./account.php");
		}
		else
		{
			include("../include/login.inc");
			echo "&lt;center&gt;&lt;font color="#FF0000"&gt;Please enter correct user ID or password&lt;/font&gt;&lt;/center&gt;";
			exit;
		}
	}
?&gt;
&lt;/body&gt;
&lt;/html&gt;
-------------------------------------------------------------------------------


Code: Select all

&lt;? 
	session_start(); 
	if (!isset($_SESSION&#1111;user_ID]))
	{
		
		//echo "No session".phpversion();
		//header("Location: ./login.php");
		//exit;
	}
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Account Information&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
	margin-left: 10px;
	margin-top: 10px;
	margin-right: 10px;
	margin-bottom: 10px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	color: #575C62;
	text-decoration: none;
}
a:hover {
	color: #FF6600;
	text-decoration: none;
}
a:active {
	color: #FF6600;
	text-decoration: none;
}
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}
--&gt;
&lt;/style&gt;

&lt;link href="../forAll.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body style="margin: 0 0 0 0"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="1" cellspacing="1"&gt;
&lt;tr valign="top"&gt;
&lt;th width="180" align="left" class="leftMain" scope="col"&gt;
&lt;table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;
&lt;th height="157" align="left" valign="top" scope="col"&gt;
&lt;table width="100%"  border="0" cellspacing="1" cellpadding="3"&gt;&lt;tr&gt;
&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./account.php"&gt;Home&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./viewgrades.php"&gt;Grades&lt;/a&gt;&lt;/th&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./changepwd.php"&gt;Change password&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th height="25" align="left" valign="middle" class="forMenu" scope="col"&gt;&lt;a href="./logout.php"&gt;Logout&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt; &lt;/th&gt;&lt;/tr&gt;&lt;/table&gt; &lt;/th&gt;
&lt;th align="left" class="rightMain" scope="col"&gt;&lt;table width="100%" height="100%"  border="0" cellpadding="10" cellspacing="1"&gt;
&lt;tr&gt;&lt;th align="left" valign="top" class="forContent" scope="row"&gt;&lt;p&gt;Hi, &lt;?php echo "$_SESSION&#1111;first]"; ?&gt;&lt;/p&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/table&gt;
&a
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Please use

Code: Select all

-tags around code to enhance readiblity.ags around code to enhance readiblity.ags around code to enhance readiblity.ags around code to enhance readiblity.ags around code to enhance readiblity.ags around code to enhance readiblity.iblity.ags around code to enhance readiblity.ags around code to enhance readiblity.ags around code to enhance readiblity.diblity.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it seems people have forgotten that the new

Code: Select all

tags support [b]labeling[/b]... :roll:[/size]

[list=1][*]quote your string literals (account.php, line 3).
[*]your call to session_start() in login.php (line 90) happens [u]after[/u] output has started. The session isn't getting set most likely.[/list]
sbprasad2000
Forum Newbie
Posts: 2
Joined: Sun Oct 10, 2004 12:15 pm

Post by sbprasad2000 »

Hi feyd,

Thanks..its working..u wont believe it I was trying to find the error from past one week.

Prasad
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

header issues, seems to be 82.3% of the peoples problem anymore

:?:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

tim wrote:header issues, seems to be 82.3% of the peoples problem anymore

:?:
82.4.......................
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

Phenom wrote:
tim wrote:header issues, seems to be 82.3% of the peoples problem anymore

:?:
82.4.......................
:D

But I think, if people read some articles and manual well, they don't have so much trouble with this. I know this header() thing is very "sensitive" but..
Whatever.
If people do it the way i told above then it would be:

27.2% :P
Locked