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

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.