第一次写php网页,不知道哪里错了,在登陆页面输入用户名和密码后,就又返回到登陆页面
如果是第一次登陆转到登陆页面,如果sesssion有纪录的话,usertype=professor就转到professorviewhandler.inc,检查有纪录后转到entry.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 $;
global $courseid;
global $studentArray;
global $courseArray;
global $Array;$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'];
$Entry=$_POST[''];
if($Entry!=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 $;
$tableName3 = "coursea4";
$result1 = mysql_query("insert into $tableName3 (courseid,studentid,) values ('$courseid','$studentid','$') ");
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 , 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"]);
$Array=array("1"=>$_POST["1"],"course2"=>$_POST["2"],
"3"=>$_POST["3"],"course4"=>$_POST["4"],
"5"=>$_POST["5"],"course6"=>$_POST["6"]);
for($index=0;$index<sizeof($studentArray);$index++){
$studentid=$studentArray[$index];
$courseid=$courseArray[$index];
$=$Array[$index];
checkData();
}
?>
如果是第一次登陆转到登陆页面,如果sesssion有纪录的话,usertype=professor就转到professorviewhandler.inc,检查有纪录后转到entry.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 $;
global $courseid;
global $studentArray;
global $courseArray;
global $Array;$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'];
$Entry=$_POST[''];
if($Entry!=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 $;
$tableName3 = "coursea4";
$result1 = mysql_query("insert into $tableName3 (courseid,studentid,) values ('$courseid','$studentid','$') ");
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 , 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"]);
$Array=array("1"=>$_POST["1"],"course2"=>$_POST["2"],
"3"=>$_POST["3"],"course4"=>$_POST["4"],
"5"=>$_POST["5"],"course6"=>$_POST["6"]);
for($index=0;$index<sizeof($studentArray);$index++){
$studentid=$studentArray[$index];
$courseid=$courseArray[$index];
$=$Array[$index];
checkData();
}
?>
解决方案 »
- PHP 登陆验证时代码有问题
- Windows下 move_uploaded_file或copy 服务器不能上传 本地可以上传 急~~~请各位大侠帮帮忙~~回答的都加分了~
- 各位大大们,请给我分析下,下面的代码,最好能够具体点,谢谢哈。。等着的
- 求一个字符串截取通用方法
- 优化获取数据库条目总数
- PHP重定向是全局参数问题?
- 求“ed2k链接”正则表达
- 请教如何将js取的时间转为用php函数取
- 好奇怪,redhat9下php文件的名字取index.php无法正常运转,而同样内容文件名改为别的就可以
- 用正则表达式preg_match_all匹配字符串?
- 求JS写的有复选框的联动菜单
- radio取值问题?
studentViewHandler.inc
<?php
// Application logic section
function checkMark(){
global $user_data;
getMark();
if ($user_data!=NULL) {
MarkViewPage();
}
return;
}
// Data access section
function getMark(){
global $studentid;
global $user_data;
$tableName1 = "coursea4";
$result1 = mysql_query("select courseid and from $tableName1 where studentid='$studentid' ");
if (!$result1) {
$error_message = "Error - the query could not be executed ";
}
else {
$row_index = 0;
while ($row = mysql_fetch_array($result1)) {
$rowSize = sizeof($row);
$user_data[$row_index] = "";
for ($fieldIndex=0; $fieldIndex < $rowSize/6; $fieldIndex++) {
$user_data[$row_index] = $user_data[$row_index]." $row[$fieldIndex]";
}
$row_index++;
}
}
return $user_data;
}
// Presentation generation section
function MarkViewPage(){
global $user_data;
//print "<form action='LoginPage.html' >";
print "<html>";
print "<head><title>Mark View Page</title></head>";
print "<body>";
print "<h2>Mark View Page</h2><br/>";
print " CourseID Mark ";
$size = sizeof($user_data);
for ($i = 0; $i < $size; $i++) {
print $user_data[$i];
print "<br/>";
}
print "</body>";
print "</html>";
}
// Main control section
checkMark();
?>
<?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 $;
global $courseid;
global $studentArray;
global $courseArray;
global $Array; $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'];
$Entry=$_POST[''];
if($Entry!=true){
include("MarkEntryPage.html");
}
else{
include("ProfessorViewHandler.inc");
}
}
}
else{ include("LoginPage.html");
$loginid=$_POST["loginid"];
$password =$_POST["password"];
include("LoginHandler.inc");
}
}
?>