Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Quiz With Php, But Without Mysql
tempest
post Jun 26 2006, 10:51 AM
Post #1


Newbie [Level 2]
**

Group: Members
Posts: 39
Joined: 19-June 06
Member No.: 25,361



Ok let`s start! Once I wrote it for school:

At first we need questions (php)
CODE
$form_block = "
<p>Quiz</p>
<form method=\"POST\" action=\"$_SERVER[PHP_SELF]\">
<p><strong>What's The Capital City Of England?</strong><br>
<input type=\"text\" name=\"q1\" value=\"$q1\" size=30></p>
<p><strong>How Many Letters Are There In The Alphabet?</strong><br>
<input type=\"text\" name=\"q2\" value=\"$q2\" size=30></p>
<p><strong>WHat's 3+10?</strong><br>
<input type=\"text\" name=\"q3\" value=\"$q3\" size=30></p>
<input type=\"hidden\" name=\"execute\" value=\"1\">
<p><input type=\"submit\" name=\"submit\" value=\"Submit\"></p>
</form>";


That takes the form of a form...
You can, of course edit the questions.
I will now break that code down and explain the different parts.

CODE
<form method="POST\" action=\"$_SERVER[PHP_SELF]\">


The reason that any "s (Double quotes) are shown after a \ (Backwards slash) is becouse the PHP Parser will spew out errors if you forget to do this.
"POST" Means that it will carry all the data from this form via POST, rather than GET.
"$_SERVER[PHP_SELF]" Means that it will load this page again to process the data from the form.

CODE
<input type="hidden\" name=\"execute\" value=\"1\">


This will tell the PHP document weather to display the form or process the results.

Then, you're gonna need to display the form

CODE
if ($execute != 1) {
echo "$form_block";
}


CODE
if ($execute != 1){


Will find out if "$execute" is not equal to 1. If not, it will display the form like so:

CODE
echo "$form_block";


Submit:

CODE
else if ($op == "ds") {


That'll do the opposite, it "$execute" IS equal to 1, it will process the answers.

Make all the answers in lower case:

CODE
strtolower($q1);
strtolower($q2);
strtolower($q3);


And the answers, you're gonna need answers

CODE

     if ($q1 == "london") {
            echo "Question 1 corect!<br/>";
            $score = "1";
         } else {
            echo "Try question one again!<br/>";
         }
         if ($q2 == "26") {
            echo "Question 2 correct!<br/>";
            $score = $score + 1;
         } else {
         echo "Try question 2 again!<br/>";
         }
         if ($q3 == "13") {
            echo "Question 3 correct!<br/>";
            $score = $score + 1;
         } else {
            echo "Try question 3 again!<br/>";
         }
}



You should be able to understand that, from what i've told you in the rest of the tut.

So the whole code is this:

CODE
<?php
$form_block = "
<p>Quiz</p>
<form method=\"POST\" action=\"$_SERVER[PHP_SELF]\">
<p><strong>What's The Capital City Of England?</strong><br>
<input type=\"text\" name=\"q1\" value=\"$q1\" size=30></p>
<p><strong>How Many Letters Are There In The Alphabet?</strong><br>
<input type=\"text\" name=\"q2\" value=\"$q2\" size=30></p>
<p><strong>WHat's 3+10?</strong><br>
<input type=\"text\" name=\"q3\" value=\"$q3\" size=30></p>
<input type=\"hidden\" name=\"execute\" value=\"1\">
<p><input type=\"submit\" name=\"submit\" value=\"Submit\"></p>
</form>";

//Display the form.
if ($execute != 1) {
echo "$form_block";
//OR
}else if ($op == "ds") {
//Process and display the results.

//Make all the user input Lower Case.
strtolower($q1);
strtolower($q2);
strtolower($q3);

//Display results.
     if ($q1 == "london") {
            echo "Question 1 corect!<br/>";
            $score = "1";
         } else {
            echo "Try question one again!<br/>";
         }
         if ($q2 == "26") {
            echo "Question 2 correct!<br/>";
            $score = $score + 1;
         } else {
         echo "Try question 2 again!<br/>";
         }
         if ($q3 == "13") {
            echo "Question 3 correct!<br/>";
            $score = $score + 1;
         } else {
            echo "Try question 3 again!<br/>";
         }
}
?>



Ofcourse you can change the questions!


Go to the top of the page
 
+Quote Post
fdpvip
post Jul 4 2006, 05:36 AM
Post #2


Newbie [Level 1]
*

Group: Members
Posts: 24
Joined: 4-July 06
Member No.: 26,038



That looks really nice, well done! I've been on so many websites that have quizzes and can't figure out how they do it until reading this. Thanks!
Go to the top of the page
 
+Quote Post
tempest
post Jul 4 2006, 08:44 AM
Post #3


Newbie [Level 2]
**

Group: Members
Posts: 39
Joined: 19-June 06
Member No.: 25,361



Pleased to help!
Go to the top of the page
 
+Quote Post
darlord
post Jul 4 2006, 10:24 AM
Post #4


Member [Level 1]
****

Group: Members
Posts: 58
Joined: 3-July 06
Member No.: 26,004



Thanks man, im gonna put this quiz on my new page. It sounds very good. rolleyes.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Complete Login System(57)
  2. Shoutbox, Made Easy(17)
  3. How To Host Ur Own Site In 2 Mins Php+mysql Needed(34)
  4. Complete Login And Registration System(9)
  5. Php Quiz Script(20)
  6. Php/mysql Login/register(2)
  7. Backing Up And Restoring Mysql Databases(10)
  8. Php Dynamic Signatures(9)
  9. Mysql Database Setup(1)
  10. A Nice Mysql Server Check(4)
  11. Install Php 5 To Work With Mysql(0)
  12. Searching With Php And Mysql(2)
  13. Installing Php + Mysql + Apache + Phpmyadmin On Windows Part 2(0)
  14. Check Referrer To Prevent Linking Yours From Other Sites(8)
  15. Starting Or Stopping Apache And Mysql Server Via Batch File(0)
  1. Cpanel Mysql Database Management(6)
  2. Simple Shoutbox(34)
  3. Simple User System(19)
  4. Adding Data To A Database And Displaying It Later(1)
  5. Getting Started With Mysql(2)


 



- Lo-Fi Version Time is now: 13th October 2008 - 10:42 PM