hello, im new here.. im a student and have a serious problem with my thesis... could anyone help me or direct me on how "to create an e-learning site in php" with a log-in page with a grading system.. any advise would really be helpful... thanks

yes...
Before you start the e-learning,keep in mine some important points...
First show all of your courses with price and brief details...and there provide questions link to ask their doubts about that course(do it by mail function...).
Provide membership means registration form and login form with session or cookies to have their rememberance.. .
provide them to pay money by online with total or installments...
Allow them to access e-learning after payment..
Provide some feedback forms and contact us form...
And provide some online examinations on that course...show all results of participated members...give rating,grades and some award certificates...
And lastly...Back end is very important to maintain all these...

thanks for.. but there is no transaction that is going to happen.. i mean the site will be uploaded in a dedicated server in one of our laboratory's, and all enrolled students in that subject shall be manually added by the administrator.... i already finished making the modules.. what i need now is making a log in for and graing form for the online assessments for the user..

A couple questions, first, for the grading form, are you showing them the full results after the exam or just the score? Do the results go to a particular person or just in a database? How are you validating that a user is authorized to access the exam page, sessions ? cookies? Below is assuming sessions.

A simple login script would be like this:

# login.php #
print '
<form action="login_check.php">
<p>Username: <input type="text" name="user" /></p>
<p>Password: <input type="password" name="pass" /></p>
<p><input type="submit" name="submit" value="submit" /></p>
<input type="hidden" name="submitted" value="1" />
</form>';

#login_check.php #
if($_POST["submitted"] == 1) {
mysql_connect($dbhost,$dbuser,$dbpass); # change to your credentials
mysql_select_db($dbname); # change to your database name


$userID = mysql_real_escape_string(stripslashes($_POST["user"]));
$passID = mysql_real_escape_string(stripslashes($_POST["pass"]));

$query = 'SELECT user,pass FROM table WHERE user = "'.$userID.'" 
AND pass = "'.$passID.'" LIMIT 1';

$result = mysql_query($query);
$count = mysql_num_rows($result);

if($count == 0) {
die(header("Location: login.php?invalid"));
}
else {
session_start();
$_SESSION["authorized"] == 1;
die(header("Location: exam.php"));
}
}

Have the exam.php check if the session variable is equal to 1, if not kick them out.

I would need to know a little more about how you have the exam setup before creating an example on grading. Is the test the same questions everytime, is it the same number of questions, are they in random order? Are they all multiple choice /True false?

thanks for the advice..

first for the exam,, after taking it,, the score will be shown for the user.. the score will go to the database and will also show in his account profile something like that..

second,, every user will have access to the exam page as soon as the administrator turns on somewhat like an exam permit button ..

third,, there will be 3 units,, and so there should be 1 exam for each unit ( 3 exam in total ).. Each exam will have different questions according to the lecture modules.. Well I think multiple choice for the exam is fine..

No problem, I'll try to answer these. I think for it to make sense, I'll need to answer the questions unordered. This is going to be long so brace yourself, and of course use this tutorial at your own risk.

Once the admin has uploaded the users to a users table. I trust the table structure will something similar to this:
ID (Integer)
USERNAME (varchar)
AUTHEXAM (varchar)
SCORE (varchar)

Since there are 3 exams, we'll use ID as a primary key with auto increment. For the USERNAME and AUTHEXAM fields, there are two ideal ways to go about this. One is you can (a) have the username listed 3 times for each exam, or (b) have the username listed once and have the authexam show an array, in this case we'll do (a) like so:

(a)
ID: 1; USERNAME: user1; AUTHEXAM: 1; SCORE: -1;
ID: 2; USERNAME: user1; AUTHEXAM: 2; SCORE: -1;
ID: 3; USERNAME: user1; AUTHEXAM: 3; SCORE: -1;


You can manually enter and update the data through phpMyAdmin or whatever your MySQL admin utility or if you have an custom interface the admin will use. Whichever you prefer.

-------------------------------------------------------

Next, I guess I should ask if the exams are meant to taken one after the other or in no particular order. Anyways, I'll assume the latter.

You can make 3 different exam pages like exam1.php, exam2.php, exam3.php, or you can pass a variable through the URL like exam.php?examID=1.

Once the admin has activated the exam for user1 for exam1:

# exam1.php # - Repeat for exam2.php and exam3.php
# for this, you need $_SESSION["username"] defined on the login page as the username from the post.

session_start();
if($_SESSION["authorized"] != 1) {
die(header("Location: notAuthorized.php"));
}
mysql_connect($dbhost,$dbuser,$dbpass); # change to your credentials
mysql_select_db($dbname); # change to your database name

$user = $_SESSION["username"];
$exam = 1; # change this to which exam they are taking be it 1, 2, or 3.

# this query checks that they the admin has activated the user and the -1 indicates they have not completed the exam already.

$query = 'SELECT * FROM usertable 
WHERE USERNAME = "'.$user.'" AND AUTHEXAM = "'.$exam.'" AND SCORE = "-1" LIMIT 1';

$result = mysql_fetch_array($query);

if(empty($result)) {
die(header("Location: notAuthorized.php"));
}

The next part of the file, first we need to know how your exam data is set up. You said multiple choice so I assume you have the bank of questions entered and their choices (up to 5) and right answer in a form like this:

exam_id (integer)
question_no (varchar)(unique)
question (text)
ans1 (text)
ans2 (text)
ans3 (text)
ans4 (text)
ans5 (text)
ans6 (varchar) - ans6 is a dummy for if they do not answer the question, leave it blank
correct (char, 2)

to keep the question_no field unique, the value should be something this 1_1, 1_2, etc. (left of the underscore is the exam id and to the right is the question number. Hopefully that makes sense.

# exam1.php continued #

$exquery = 'SELECT * FROM examtable WHERE exam_id = "'.$exam.'"';
$exresult = mysql_query($exquery);

print '
<form action="examcheck.php">
<p> Exam '.$exam.' </p>';

$questionCount = 1;
$selectedAnswer = 1;

while ($exrow = mysql_fetch_array($exresult)) { #outer while
$question_no = $exrow["question_no"];
$question = stripslashes($exrow["question"]);

print '
<p><b>'.$questionCount.'</b>. '.$question.'</p>';

$count = 1;	
$char = 65; # this is the decimal format for the answer letter (A, B, C, D, E)

while($count <= 5) { # inner while
$answerOption = stripslashes($examRow['A'.$count]);

print '<p>';

if($answerOption) {
print '
<input type="radio" name="ans'.$selectedAnswer.'" 
value="'.$exrow["question_no"].' ans'.$count.'" />
'.chr($char).') '.$answerOption.' 
<br />';
} # end if

print '</p>';

$count++;
$char++;
} #end inner while

print '
<input style="visibility:hidden" type="radio" name="ans'.$selectedAnswer.'" 
value="'.$exrow["question_no"].' ans6" checked="checked">';
		
$selectedAnswer++;
$questionCount++;

} #end outer while

print '
<input type="hidden" name="exam_id" value="'.$exam.'" />
<input type="hidden" name="user" value="'.$user.'" />
<input type="hidden" name="totalQuestions" value="'.$questionCount.'" />
<input type="hidden" name="submitted" value="1" />
<input name="finished" type="submit" value="1" />
</form>';

This will layout out the exam in a very simple format with just paragraphs and bolding with radio buttons and only one right answer.

------------------------------------------------------------------

Last, for grading the exam, we'll grade then enter into a database and then show to the user as indicated:

# examcheck.php # 
if($_POST["submitted"] == 1) { # outer if

mysql_connect($dbhost,$dbuser,$dbpass); # change to your credentials
mysql_select_db($dbname); # change to your database name

$totalQuestions = $_POST["totalQuestions"];
$questionsRight = $totalQuestions;

$exam_id = $_POST["exam_id"];
$user = $_POST["user"];
$count = 1;

for($i = 1; $i <= $question_total; $i++) {

$submittedAnswer = $_POST['ans'.$count];
list($question_no,$question_ans) = explode(" ",$submittedAnswer);

$query = 'SELECT exam_id, question_no, question, '.$question_ans.', correct 
FROM examtable WHERE exam_id = "'.$exam_id.'" 
AND question_no = "'.$question_no.'"';

$result = mysql_query($query);

$row = mysql_fetch_array($result);
mysql_free_result($result);
		
$question_number = $row["question_no"];
$question = stripslashes($row["quesiton"]);				
$correctAnswer = $row["correct"];

if($question_ans != $correctAnswer) {	$right--; }

$count++;

} # end outer if

$score = ($right/$totalQuestions)*100;
$score = number_format($score,2);

# we have our score so enter it into the database;

$uquery = 'UPDATE usertable SET SCORE = "'.$score.'" 
WHERE USERNAME = "'.$user.'" 
AND AUTHEXAM = "'.$exam_id.'" LIMIT 1';

$uresult = mysql_query($uquery);

# We will encode the score data to be shown on the result page

$outputScore = $right." / ".$totalQuestions." - ".$score."%";
$userAndScore = $user." - ".$outputScore;
$outputEncoded = base64_encode($userAndScore);

# we now have the score encoded so we redirect to the results page:

die(header("Location: results.php?s=".$outputEncoded));

-------------------------------------------------------------------------

For the final part, we show the user their score:

# results.php #



# assign the user to a regular variable



# first destroy the session variables so they can't hit the back button and resubmit

session_start();
$_SESSION = array();
session_destroy();

$outputDecoded = base64_decode($_GET["s"]);

# last print the exam results with username:

print '<p>'.$outputDecoded.'</p>';

print '<p><a href="somewhere.php">Click here</a> to get out of here.</p>';

base64 encode/decode is just one way to easily pass it through the browser, you can use an encryption here if you want to get advanced.

So I hope this helps. This example above will verify a user can take the exam, present the exam, grade the exam, update the database and show the score to the user.

I didn't have time to test it so there may be a few parse errors and typos. I'll leave the style and formatting of the HTML to you.

Comments
willing to help others...

thanks a lot dude.. this is a very big help,.. enweyz,, i'll try to analyze the script more... i'll just post some questions later if ever some wierd thing happens.. thanks again..

This article has been dead for over six months. Start a new discussion instead.