Good day Admins,

I have now variables

$learner_id
$student_pasword

The learner_id and student_password are being used as their log in accounts. While the student_id is being used as their unique id and it is auto-incremented.

Here are my codes.

Student_login_handler.php

<?php
session_start();
include 'Connect.php';
$flag = "";
$learner_id = $_POST['learner_id'];
$student_password =  $_POST['student_password'];
$query = "select last_login_date from student_information where learner_id='$learner_id' and student_password='$student_password'";
$result = mysql_query($query,$link_id);
if(mysql_error() != null){
die(mysql_error());
}
if($date = mysql_fetch_array($result))
{
$lastdate = $date['last_login_date'];
$date2 = date("d-m-Y h:i A",strtotime($lastdate));
$_SESSION["user_id"] = $_POST["student_id"];
$_SESSION["lastlogin"] =$date2;
$_SESSION["type"] = "Student";
mysql_query("UPDATE student_information SET last_login_date=now() where student_id='$GET[id]'",$link_id);
if(mysql_error() != null){
die(mysql_error());
}
header("location:  Student_Home.php?id={$student_id}"); 
die();
}
else
{
$flag = "invalid";
header("location:Student_login.php?flag=$flag");
die();
} 
?>

Here is my Student_login.php

<td width="35%" align="left" class="style7 style1">Learner Id : </td>
           <td width="65%" align="left"><input name="learner_id" type="text" id="learner_id" action="Student_Home.php" method="post"></td>
        </tr>
        <tr bgcolor="#E1E1E1" class="stylesmall">
           <td align="left" class="style7 style1">Password:</td>
           <td align="left"><input name="student_password" type="password" id="student_password"></td>
        </tr>
        <tr bgcolor="#E1E1E1">    
           <td colspan="2" align="center">&nbsp;
             <?php if(!empty($_GET['flag']) && $_GET['flag'] == "invalid") { ?>
             <span class="stylered style1">Invalid Learner Id or Password</span>
             <?php }?></td>
        </tr>
        <tr bgcolor="#E1E1E1">
           <td colspan="2" align="center">
                <p><input name="login" class="style10" type="submit" id="login" value="Login"></p> 

This is so far what i've got and it's wrong. Help me to modify this gentlemen to achieve the objectives given above.

It directs me to URL
http://localhost/a/S...nt_Home.php?id=

which i expect to be

http://localhost/a/S..._Home.php?id=51 (51 is the auto-incremented student_id, bears unique id of student)

Please help me modify the codes.

Recommended Answers

All 10 Replies

Member Avatar for diafol

Help me to modify this gentlemen to achieve the objectives given above.

Not prepared to accept help from our female members then?

Out of interest why are you insisting that users remember an id number? Usernames are so much easier to remember. I don't know of many (if any?) sites that insist on this.

ok what i can see from this is
header("location: Student_Home.php?id={$student_id}");
the $student_id isn't assigned to anything isn't it supposed to be
header("location: Student_Home.php?id={$learner_id}");??
i cannot see $student_id declared anywhere

Hello Diafol,

Apology on that, any gender will do :-).

I mean that user id (the auto incremented one) will be only use in URL to call students information.

Their desired learner id will still be used during their log in. Well, that s what i wanted to happen (not sure though if my codes fit in that objective). Please need a help then.

Hello Sammys. Man,

Thank you for that observation. Yeah, your right,, what i have missed is how to properly declared that assigned auto-incremented $student_id variable on the table. For the purpose of calling the student information i have entered and in the "Administrator" session.

Could you help me on that please.

i need more information, i think the language barrier is not helping, what exactly do you need?
i will help as much as i can, but need the full description of what you need.

Sorry for my english.

-im currently developing a log in system for students.
-each students need to log in using their $learner_id and $student_password.
-there are many students who will log in so i am assigning auto incremented unique id for each of them which is the variable $student_id.

-when a student succesfully logged-in, he must be directed to his Student_Home.php.
-Student_Home.php is where his student informations are present. Different student information for every student.(so it means different $student_id assigned for each of them)

My problem: the current situation.

-When a student logged-in he is directed to Student_Home.php but his student information is not present there.

-This is the URL http://localhost/a/S...nt_Home.php?id=

but when i type URL http://localhost/a/S...nt_Home.php?id=51 (see the 51)

the student information of student, bearing the $student_id (51) is present.

What i wanted:

When a particular student logged in he must be automatically directed to
http://localhost/a/S...nt_Home.php?id=51 (51 is an example assigned to a specific student as auto incremented value).

Need to modify those codes on my first post. Please help

ok, i think your problem is simple,
you are posting you 'learner_id' from the form to the login_handler,
and you have set your variable to $learner_id,
but your location change header is pointing to $student_id,

header("location: Student_Home.php?id={$student_id}");

$student_id doesn't exist change it to header("location: Student_Home.php?id={$learner_id}");

Thank you for that response Sammys.Man.
The URL know identifies the learner_id but still i cant extract the information of students

$student_id doesn't exist

Please help me to make it exist. Help me to declare this variable.

header("location: Student_Home.php?id={$student_id}");

this header location must remain.all i need is to declare the student_id variable but i dont know how to code it.THis is the one i missed.

I am changing 4 lines of your student_login_handler.php

Line 7

$query = "select student_id,last_login_date from student_information where learner_id='$learner_id' and student_password='$student_password'";

Line 16

$_SESSION['user_id'] = $date['student_id'];

Line 19

mysql_query("UPDATE student_information SET last_login_date=now() where student_id='{$_SESSION['user_id']}'",$link_id);

Line 23

header("location:  Student_Home.php?id={$_SESSION['user_id']}"); 

whew!! Urtrivede ['posting virtouso']

YOU ARE THE GREAT!!! i have been through different sites and your the only one who had solved this missing pieces with just one look.

Uhh man, if your just here, i would offer you a drink..
Thanks much bro...

Mail me if you'd like to visit Philippines!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.