<pre>
Thank you very much for your help! What I was trying to say was that I tried two different text files (with "tab" separated and "|" separated file).... The actual command that I used was:
LOAD DATA LOCAL INFILE 'tbl_student.txt' INTO TABLE tbl_student FIELDS TERMINATED BY '\t' ENCLOSED BY '\"' ESCAPED BY '\' LINES TERMINATED BY '\n'
Once this is done, I can see that all the data are entered. By using select * from tbl_student
The problem is that if I want to use the combination of userid, password, and student_id to see the exam scores, the combination wouldn't work at all... 🙁
If I do the registration through the the net (rather than importing the textfile into the db), the login and display seem to work.
Here are the code.... And sorry about this long....
For the database, it has three tables:
tbl_student contains fields: student_id, userid, pswd, f_name, l_name, email, major, minor, year
tbl_score contains fields: event_id, student_id, score
tbl_event contains feilds: event_id, event_type
My idea was that after each exam (with student_id and event_id attached), I can just dump the data (student_id, event_id, score) in the tbl_score table. Individual record can be retrieved based on their userid and password and student_id.
The codes were:
common.inc: contains the database name; direcotry; and login information
==============
functions.php: three functions
<?php
require 'common.inc' ;
//funcation displayerrmsg();
//function authenticateuser();
//function deletecookies();
//Display error messages
function displayerrmsg( $message ) {
printf("%s\n !!!!\n", $message);
}
//Authenticate users
function authenticateuser($form_userid, $form_pswd, $form_stuid) {
global $DB_SERVER, $HTTP_HOST, $DB_LOGIN, $DB_PASSWORD, $DB, $DOCROOT ;
//open a persistent connection
if (!($link = mysql_pconnect ($DB_SERVER, $DB_LOGIN, $DB_PASSWORD))) {
displayerrmsg(sprintf("internal error %d: %s \n", mysql_errno(), mysql_error()));
return 0; }
//Do the user/password check
$result=mysql_db_query("$DB", "select * from tbl_student WHERE userid='$form_userid'");
if (!($result)) {
displayerrmsg(sprintf("internal error %d: %s \n", mysql_errno(), mysql_error()));
return 0;
}
$row = mysql_fetch_array($result);
if (($row) &&
(($form_pswd==$row["pswd"] && $form_pswd!="") &&
($form_stuid==$row["student_id"] && $form_stuid!="")) ) {
return1;
} else {
return 0;
}
}
// deletes cookies
function deletecookies() {
setcookie("cookie_userid","");
setcookie("cookie_pswd","");
setcookie("cookie_stuid","");
}
===============
registration.php
<?php
require 'functions.php' ;
//I need all the information from registration.html (input data)
if ( ((trim($form_userid)=="") ||
(trim($form_pswd)=="") || (trim($form_pswd1)=="") ||
(trim($form_ssn)=="") || (trim($form_f_name)=="") ||
(trim($form_l_name)=="") || (trim($form_email)=="") ||
(trim($form_year)=="") || (trim($form_major)=="")) ) {
header("Location:http://$HTTP_HOST/$DOCROOT/error1.shtml");
exit();
// passwords should be identical
} else if ($form_pswd != $form_pswd1) {
// If both the passwords are not the same then generate error message
header("Location:http://$HTTP_HOST/$DOCROOT/error3.shtml");
exit();
}
else {
// Open a persistent connection with the Database
if (!($link = mysql_pconnect($DB_SERVER, $DB_LOGIN, $DB_PASSWORD))) {
displayerrmsg(sprintf("internal error %d:%s\n", mysql_errno(), mysql_error()));
exit() ;
}
// Create the user record
if (!($newresult = mysql_db_query ($DB, "INSERT INTO tbl_student
(student_id, userid, pswd, f_name,l_name,email,major, minor, year)
VALUES
('$form_userid','$form_pswd','$form_ssn','$form_f_name',
'$form_l_name','$form_email','$form_major','$form_minor', '$form_year')"))) {
displayerrmsg(sprintf("internal error %d: %s\n", mysql_errno(), mysql_error()));
exit() ;
} else {
/ If Registration Successful, then display, else display error msg /
header("Location:http://$HTTP_HOST/$DOCROOT/reg-success.shtml");
exit();
}
}
?>
After registration, Login session can be used:
login.php
<?php
require 'functions.php';
//delete all the old cookies, which one is right?
deletecookies();
// setcookie("cookie_userid","");
// setcookie("cookie_pswd","");
// setcookie("cookie_pswd","");
// do I need this?
// $userid=ereg_replace(" ","",$form_login_userid);
// $pswd=ereg_replace(" ","",$form_login_pswd);
// $stuid=ereg_replace(" ","",$form_login_stuid);
if (authenticateuser($form_userid, $form_pswd, $form_stuid)) {
setcookie("cookie_userid",$form_userid);
setcookie("cookie_pswd",$form_pswd);
setcookie("cookie_stuid",$form_stuid);
printf("$cookie_userid\n\n");
printf("$cookie_pswd\n\n");
printf("$cookie_stuid");
header("Location:http://$HTTP_HOST/$DOCROOT/grade-inquiry.php");
// exit();
} else {
header("Location:http://$HTTP_HOST/$DOCROOT/error1.shtml");
exit();
}
?>
==========================
Lastly logout...
<?php
require 'functions.php';
if (!authenticateuser($cookie_userid, $cookie_pswd, $cookie_stuid)) {
header("Location:http://$HTTP_HOST/class/com300/");
exit();
} else {
deletecookies();
// setcookie("cookie_userid","");
// setcookie("cookie_pswd","");
// setcookie("cookie_stuid","");
// printf("$cookie_userid");
header ("Location:http://$HTTP_HOST/class/com300/");
exit();
}
?>
</pre>