Jump to content

Recommended Posts

Good Day PHP Freaks,

 

I would like to ask help from all of you. It seems my Log-in button does not direct to Home (Student_Home.php). Student ID and password has been registered to database already. 

 

Here is the script for Student_login.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Login Page</title>
<link rel="stylesheet" href="Style.css" type="text/css"/>
<script type="text/javascript">
function validate() 
{
	if(document.form1.student_id.value=="")
	{
	  alert("Please enter your login Id.");
	  document.form1.student_id.focus();
	  return false;
	}
	if(document.form1.student_password.value=="")
	{
	  alert("Please enter your password.");
	  document.form1.student_password.focus();
	  return false;
	}
}
</script>
<style type="text/css">
<!--
body {
	background-color: #0099FF;
}
-->
</style></head>
<body onLoad="javascript:document.form1.student_id.focus()">
<form name="form1" method="post" action="Student_login_handler.php" onSubmit="return validate();">
  <table width="100%" height="100%" >
    <tr>
      <td height="15%"><?php include 'Header.php';?></td>
    </tr>
    <tr>
      <td width="100%" height="80%" align="center" valign="baseline"><table width="90%" >
        <tr>
          <td width="8%"><a href="index.php" class="stylelink" style="text-decoration:none; font-family: "Times New Roman", Times, serif;">Home</a></td>
          <td width="35%" align="center"> </td>
          <td width="27%"> </td>
          <td width="30%" align="right"><a href="Student_Registration.php" class="stylelink" style="text-decoration:none ; font-weight: bold;">New Student Click Here</a></td>
        </tr>
        
        <tr>
          <td> </td>
          <td> </td>
          <td> </td>
          <td> </td>
        </tr>
        
          <?php if(!empty($_GET['flag']) && $_GET['flag'] == "success") { ?>
		  <tr>
		       <td class="stylegreen" colspan="4" align="center">Congratulations! You Are successfully registered. You can use your Login Id and Password to login to your account.</td>
		  </tr>
		  <?php 
		  }
		  else if(!empty($_GET['flag']) && $_GET['flag'] == "exists") { ?>
		  <tr>
		       <td class="stylered" colspan="4" align="center">This Login Id( <?=$_GET['student_id']?>) already exists.Please, try again with another Login Id</td>
		  </tr>
		  <?php 
		  	}else if(!empty($_GET['flag']) && $_GET['flag'] == "error") {
		  ?>
         	<tr>
		       <td class="stylered" colspan="4" align="center">Error while inserting data. Please, try again.</td>
		  </tr>
		  <?php
		  	}
		  ?>
        <tr>
          <td> </td>
          <td> </td>
          <td> </td>
          <td> </td>
        </tr>
        <tr>
          <td> </td>
          <td> </td>
        </tr>
        <tr>
          <td colspan="4"><table width="30%"  border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#CCCCCC" bgcolor="#CCCCCC">
            <tr align="center" bgcolor="#999999">
              <td colspan="2" bgcolor="#99CC33" class="stylebig">Student Login Here</td>
                </tr>
            <tr bgcolor="#E1E1E1" class="stylesmall">
              <td width="35%" align="left" class="style7">Login Id : </td>
                <td width="65%" align="left"><input name="student_id" type="text" id="student_id"></td>
              </tr>
            <tr bgcolor="#E1E1E1" class="stylesmall">
              <td align="left" class="style7">Password:</td>
                <td align="left"><input name="student_password" type="password" id="student_password"></td>
              </tr>
            <tr bgcolor="#E1E1E1">
			
	
			
              <td colspan="2" align="center"> 
			 	<?php if(!empty($_GET['flag']) && $_GET['flag'] == "invalid") { ?>
                <span class="stylered">Invalid Login Id or Password</span>
				<?php }?>				</td>
            </tr>
            <tr bgcolor="#E1E1E1">
              <td colspan="2" align="center"><input name="login" class="style10" type="submit" id="login" value="Login">
                <input name="close" type="button" id="close" class="style10" value="Close" onClick="self.location='index.php'">                </td>
                </tr>
          </table></td>
          </tr>
      </table></td>
    </tr>
    <tr>
      <td height="5%" align="center"><?php include 'Footer.php';?></td>
    </tr>
  </table>
</form>
</body>
</html>

,,and here is the Student_login_handler.php.

<?php
	session_start();
	include 'Connect.php';
	$flag = "";
	$student_id = $_POST['student_id'];
	$st_pass =  $_POST['student_password'];
	$query = "select last_login_date from student_information where student_id='$student_id' and student_password='$student_password' and student_status ='Enable'";
	$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['student_id'] = $_POST['student_id'];
		 $_SESSION['lastlogin'] =$date2;
		 $_SESSION['type'] = "Student";
		 mysql_query("update student_information set last_login_date=now() where student_id='$student_id'",$link_id);
		 if(mysql_error() != null){
			die(mysql_error());
		}
		 header("location:Student_Home.php");
		 die();
	}
	else
	{
		$flag = "invalid";
		header("location:Student_login.php?flag=$flag");
		die();		
	} 
	
?>

It keeps saying "Invalid ID or password" 

 

Hope you can help me troubleshoot this..

Link to comment
https://forums.phpfreaks.com/topic/286626-log-in-button-wont-direct-to-home/
Share on other sites

echo your $query variable to see if it contains expected values for the student_id and student_password. if it does, copy the resulting sql query and run it directly against your database using your favorite database management tool (i.e. phpmyadmin or similar) to see if it actually matches a row in your database table. if it doesn't, determine which of the three values in the WHERE clause don't match the row you have in your database table.

 

edit: also, what does var_dump($date); show?

Edited by mac_gyver

thank you mac_gyver, 

 

i will try it now. but in case it still doesn't run do you have any suggested codes to replace what i have? and what part i need to replace.

 

Im very much sorry if this questions are novice. i am just new in PHP.

 

 

+ Options

 
  student_id student_password first_name last_name registration_date gender date_of_birth student_status contact_no grade LRN email1 email2 address description LRCFORM image last_login_date   hanspeare 765632 hanspeare chavez 2014-02-27 Male 1982-01-18 Disable 09076317083 Grade 7 2011-81286 hanspeare@gmail.com hanspeare@yahoo.com Purok 8, Poblacion, Prosperidad Agusan del Sur Enabled   hanspeare_morn.jpg 2014-02-27 13:35:36 rodrigo 123 verger limas 2014-02-27 Male 2004-01-13 Disable 09081845678 Grade 7 2014-01 xmkslm@yahoo.com mcsldkn@cwle cdslknwl cldnnls   rodrigo_155291_1682944869284_1622405_n.jpg 2014-02-27 13:47:32 van van van dam 2014-02-27 Female 1989-01-18 Disable 09076789087 Grade 8 2011-01 vandam@yahoo.com damvan@yahoo.com ve geer rethe rhrhtr   van_before.jpg 2014-02-27 14:32:16 jan jan fwfwe feawfrw 2014-02-28 Female 1996-12-12 Disable

 

Edited by Shadow_Walker

i already change the LINE 6 of Student_Registration_Handler.php 

from 

$st_pass = $_POST['student_password'];

 

to

 

$student_password = $_POST['student_password'];

 

still Invalid Log in ID and password even it was entered correctly according to database. Please help..

+ Options

 

  student_id student_password first_name last_name registration_date gender   date_of_birth   student_statusdot.gif     contact_no

 jenny                       777         jenny        hermoso   2014-03-02         Female 1980-11-24        Enable               09107757753

i have managed to edit some of my codes and i registered another student id "jenny" and password "777". It shows that she is "enable" on student status unlike the previous one..but still the said student can't log in using her id and password.

Edited by Shadow_Walker
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.