美好的一天PHP向导,
我想请求各位的帮助。看来我的登录按钮没有指向Home(Student_Home.php)。学生证和密码已经注册到数据库。
* 以下是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>
* ,这里也是Student_login_handler代码*
<?php
session_start();
include 'Connect.php';
$flag = "";
$student_id = $_POST['student_id'];
$student_password = $_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();
}
?>
* * *一直说“无效的ID或密码”
希望你能帮我解决这个问题..
答案 0 :(得分:0)
我已经遇到了这个问题,可能header()
功能不起作用。以下任何地方都是解决此问题的两种解决方案,
使用PHP,您只需在首发 php 的第一行添加 ob_start(); 功能。
<?php
ob_start();
.....
.....
使用JavaScript重定向 Student_Home.php
<script type="text/javascript">
window.navigate("http://www.url.com/Student_Home.php");
</script>
另一个JavaScript函数
<script type="text/javascript">
window.location="http://www.url.com/Student_Home.php";
</script>
希望这对你有帮助!