Jump to content

[SOLVED] Problem with Login Session


Nazirul

Recommended Posts

Hello

 

I am having a problem with session for log in... please take a look at the following code:

 

		if ($option == 'student'){
			$sql = "SELECT * FROM user WHERE User_ID = '$studentId' AND User_Password ='$pswd'";
   				$result = mysql_query($sql)or die('Query failed. ' . mysql_error()); 
			$row = mysql_fetch_array($result, MYSQL_ASSOC);
  			if (mysql_num_rows($result) == 1) 
			{
			$_SESSION['User_ID']=1;
			$_SESSION['User_ID']=$studentId;
			$_SESSION['clerkId2']=$row['clerkId'];

			?>
			<script language="JavaScript">
                location.href='StudentIndex.php';
                </script>
                <?php
			exit;
			}	
			else
			{
			?>
			<script language="JavaScript">
			alert("Wrong username and password.");</script>
			<?php
			}
		}

 

from the code, i have assign the session " $_SESSION['User_ID']=1; "

 

in the StudentIndex.php page, i have assigned the following code for identifying the session

 

if($_SESSION['User_ID']!=1) {
$restrict = "login.php?error=You Must Login First";
header("Location: $restrict");
exit;
}

 

the problem is, even though i have a correct user ID and password,.. i still cant access the StudentIndex.php ...  ???

 

thanks everyone  ;D

Link to comment
https://forums.phpfreaks.com/topic/154243-solved-problem-with-login-session/
Share on other sites

            $_SESSION['User_ID']=1;
            $_SESSION['User_ID']=$studentId;

 

Why is there two of the same session variable with different data?

 

lol... this is the answer... how can i miss it... duhh :D

thanks CloudSex13  and everyone...  :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.