php用户登录,帮我看一下哪错了,谢谢~
第一次写php网页,不知道哪里错了,在登陆页面输入用户名和密码后,就又返回到登陆页面
如果是第一次登陆转到登陆页面,如果sesssion有纪录的话,usertype=professor就转到professorviewhandler.inc,检查有纪录后转到markentry.html页面登记成绩
如果usertype=student就转到studentviewhandler.inc,显示该学生的所有成绩
不知道是那里语法或者逻辑错误了,改了好久,还是不行,麻烦帮忙看一下,谢谢。
-------------------------------------------
FrontController.php
<?php
// Global variable section
$error_message = NULL;
$loginid=NULL;
$password=NULL;
$dbh=NULL;
$dbConnection=NULL;
$userType=NULL;
$flag=NULL;
// Application logic section
function checkUserAccount() {
global $loginid;
global $password;
global $userType;
include("LoginHandler.inc");
if(!$userType) {
return $flag = -1;
}
else {
if($usertype="student"){
$studentid=$loginid;
include("StudentViewHandler.inc");
}
elseif($usertype="professor") {
$professorid=$loginid;
include("ProfessorViewHandler.inc");
}
return $flag = 1;
}
}
// Data access section
function getUserData(){
$tableName = "useraccounta4";
$result = mysql_query("select * from $tableName where loginid='$loginid' and password=sha1('$password')");
if (!$result) {
$error_message = "Error - the query could not be executed <br/>";
}
else {
$row_index = 0;
while ($row = mysql_fetch_array($result)) {
$getuserType = $row;
}
}
return $getuserType;
}
// Presentation generation section
// Main control section
global $loginid;
global $password;
global $userType;
global $dbh;
global $dbConnection;
global $professorid;
global $studentid;
global $mark;
global $courseid;
global $studentArray;
global $courseArray;
global $markArray;
$serverURL = "localhost";
$userIdb = "root";
$passwordb = "";
$dbh = mysql_connect($serverURL, $userIdb, $passwordb);
if (!$dbh) {
$error_message = "Error - Could not connect to MySQL <br/>";
}
else {
$databaseName = "huangl";
$dbConnection = mysql_select_db($databaseName);
if (!$dbConnection) {
$error_message = "Error - Could not select the database <br/>";
}
sesson_start();
if(isset($_SESSION['usertype'])&&$_SESSION['usertype']!=""){
$userType=$_SESSION['usertype'];
if($userType=="student"){
$studentid=$_SESSION['studentid'];
include("StudentViewHandler.inc");
}
if($userType="professor"){
$professorid=$_SESSION['professorid'];
$markEntry=$_POST['mark'];
if($markEntry!=true){
include("MarkEntryPage.html");
}
else{
include("ProfessorViewHandler.inc");
}
}
}
else{ include("LoginPage.html");
$loginid=$_POST["loginid"];
$password =$_POST["password"];
include("LoginHandler.inc");
}
}
?>
----------------------------------------------------------------
LoginHandler.inc
<?php
// Application logic section
function checkAccount(){
global $find;
getUserData();
if ($find==-1) {
LoginErroePage();
}
else {
return $find=1;
}
}
// Data access section
function getUserData(){
global $loginid;
global $password;
global $userType;
global $find;
global $posId;
$tableName = "useraccounta4";
$result = mysql_query("select * from useraccounta4 where loginid='$loginid' and password=sha1('$password') ");
if (!$result) {
$find=-1;
return $find;
}
else {
while ($row = mysql_fetch_array($result)) {
$userType = $row["usertpye"];
$posId=$row["professorOrStudentid"];
//$userType = $row[2];
//$posId=$row[3];
}
$find=1;
}
return $userType;
}
?>
<?php
// Presentation generation section
function LoginErroePage(){?>
<html>
<head> <title> Login Error Page </title>
</head>
<body>
<h>Login information is invalid, please enter again.</h>
<form action="FrontController.php"/>
<input type="submit" name = "submit" id = "submit" value="Go back">
</form>
</body>
</html>
<?php }
?>
<?php
// Main control section
global $loginid;
global $password;
global $userType;
global $find;
global $posId;
checkAccount();
if($find==1){
session_start();
session_register('usertype');
$_SESSION['usertype']=$userType;
if($userType=="student"){
session_register('studentid');
$_SESSION['studentid']=$posId;
}
if($userType="professor"){
session_register('professorid');
$_SESSION['professorid']=$posId;
}
include("FrontController.php");
}
?>
_________________________________________________
professorViewHandler.inc
<?php
// Application logic section
function checkData(){
global $pFind;
global $sFind;
checkP();
checkS();
if ($pFind==-1||$sFind=-1) {
MarkEntryConfirmOrErrorPage();
}
elseif ($pFind==1&&$sFind==1) {
addData();
}
return;
}
// Data access section
function checkP(){
global $professorid;
global $courseid;
global $pFind;
$tableName1 = "courseinfoa4";
$result1 = mysql_query("select professorid from $tableName1 where courseid='$courseid' ");
$pid = mysql_fetch_array($result1);
if(!$pid||$pid[0]!=$professorid){
return $pFind=-1;
}
elseif ($pid[0]==$professorid){
return $pFind=1;
}
}
function checkS(){
global $studentid;
global $courseid;
global $sFind;
$tableName2 = "courseregistrationa4";
$result2 = mysql_query("select studentid from $tableName2 where courseid='$courseid' ");
$sid = mysql_fetch_array($result2);
if(!$sid||$sid[0]!=$studentid){
return $sFind=-1;
}
elseif($sid[0]==$studentid){
return $sFind=1;
}
}
function addData(){
global $studentid;
global $courseid;
global $mark;
$tableName3 = "coursemarka4";
$result1 = mysql_query("insert into $tableName3 (courseid,studentid,mark) values ('$courseid','$studentid','$mark') ");
return;
}
?>
<?php
// Presentation generation section
function MarkEntryConfirmOrErrorPage(){
?>
<html>
<head> <title> Mark Entry Confirm or Error page </title>
</head>
<body>
<h><?php
global $professorid;
global $pFind;
global $sFind;
global $studentid;
if($pFind==-1&&$sFind==1){ print ("$courseid is incorrect ,please enter again" );}
elseif($pFind==1&&$sFind==-1){ print ("$studentid is incorrect ,please enter again");}
elseif($pFind==1&&$sFind==1){ print ("$courseid and $studentid are incorrect ,please enter again");}
else{
print("$courseid and $studentid are correct ,mark entry confirm.");
}
?>
</h>
<form action="MarkEntryPage.html"/>
<input type="submit" name = "submit" id = "submit" value="Go back">
</form>
</body>
</html>
<?php
}
?>
<?php
// Main control section
$studentArray=array("student1"=>$_POST["student1"],"student2"=>$_POST["student2"],
"student3"=>$_POST["student3"],"student4"=>$_POST["student4"],
"student5"=>$_POST["student5"],"student6"=>$_POST["student6"]);
$courseArray=array("course1"=>$_POST["course1"],"course2"=>$_POST["course2"],
"course3"=>$_POST["course3"],"course4"=>$_POST["course4"],
"course5"=>$_POST["course5"],"course6"=>$_POST["course6"]);
$markArray=array("mark1"=>$_POST["mark1"],"course2"=>$_POST["mark2"],
"mark3"=>$_POST["mark3"],"course4"=>$_POST["mark4"],
"mark5"=>$_POST["mark5"],"course6"=>$_POST["mark6"]);
for($index=0;$index<sizeof($studentArray);$index++){
$studentid=$studentArray[$index];
$courseid=$courseArray[$index];
$mark=$markArray[$index];
checkData();
}
?>