php用户登录,帮我看一下哪错了,谢谢~

happyhly523 2008-03-25 09:11:07
第一次写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();
}
?>
...全文
162 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
striker_un 2008-03-26
  • 打赏
  • 举报
回复
代码可读性极差. 你就不愿意多劳动一下,用
//这个来包装一下...



<?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");
}
}
?>


kukulu00 2008-03-25
  • 打赏
  • 举报
回复
好长的代码。。。。
happyhly523 2008-03-25
  • 打赏
  • 举报
回复
对不起哦

我在试试看
zmouki 2008-03-25
  • 打赏
  • 举报
回复
告你个最苯办法?用echo "test";在你觉得有问题的地方,一行一行的查,就知道问题在哪了!还有,不要把你所有的代码都拿出来让人看,尽量说明你的问题,这样即可以节约你的时间,也能节约大家的时间。
happyhly523 2008-03-25
  • 打赏
  • 举报
回复
-----------------------------------------------
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 = "coursemarka4";
$result1 = mysql_query("select courseid and mark 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();
?>

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧