|
|
|
|
![]() ![]() |
Mar 19 2005, 04:30 AM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 208 Joined: 27-January 05 From: LI, New York Member No.: 3,448 |
Hello all,
A little bit back I decided to make a quiz scriptjust out of no where lol. However it doesnt do anything special but I am going to make an email mod for it so that it will email results to your email address. So here is the basis of it. INSTRUCTIONS: Open a new page in your text editor and paste in the following code. CODE <?php $qid = "Quiz ID-00"; ?> <html> <head> <title><? echo "Gamers Pub $qid"; ?></title> </head> <body> <p><h3><? echo "SiteName $qid"; ?></h3></p> <form action="results.php" method="post"> <p>Username: <input type="text" name="name"></p> <p>1.) Question number one is?<br> <input type="radio" name="q1" value="Answer1"> Answer1<br> <input type="radio" name="q1" value="Answer2"> Answer2</p> <p>2.) Question number two is?<br> <input type="radio" name="q2" value="Answer1"> Answer1<br> <input type="radio" name="q2" value="Answer2"> Answer2</p> <p>3.) Question number three is?<br> <input type="radio" name="q3" value="Answer1"> Answer1<br> <input type="radio" name="q3" value="Answer"> Answer2</p> <p>4.) Question number four is?<br> <input type="radio" name="q4" value="Answer1"> Answer1<br> <input type="radio" name="q4" value="Answer2"> Answer2</p> <p>5.) Question number five is?<br> <input type="radio" name="q5" value="Answer1"> Answer1<br> <input type="radio" name="q5" value="Answer2"> Answer2</p> <p><input type="submit" name="submit" value="Submit Quiz"></p> <input type="hidden" name="qp" value="quiz00.php"> </form> </body> </html> and then save it as quiz00.php and edit it obiously, lol to what you want. I shouldnt be hard because its mostly just html. But NOTE that if you go over 5 questions then you need to modifiy the php script that shows the results to display those added questions. Here is the results page which displays the results from the forms. Open up a new page in your text editor and paste in the following code. CODE <?php $title = "Quiz Results"; echo "<title>$title</title>"; // Below gets the answers from the page before // if (isset ($_POST['submit'])) { $name = $_POST['name']; $q1 = $_POST['q1']; $q2 = $_POST['q2']; $q3 = $_POST['q3']; $q4 = $_POST['q4']; $q5 = $_POST['q5']; $qp = $_POST['qp']; } // Below checks to see if you forgot anything // if ($name == "") { die ("You forgot something, go back and check over your quiz."); } if ($q1 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q2 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q3 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q4 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q5 == "") { die ("You forgot something, go back and check over your quiz."); } // Below is where the answers are actually displayed // { echo<<<EOT <p>Results: $name<br> 1.) $q1<br> 2.) $q2<br> 3.) $q3<br> 4.) $q4<br> 5.) $q5</p> <p><a href="$qp">Go Back To Quiz?</a> EOT; } ?> and then save it as results.php. Also this time I put comments in there which should give you some hints to what is going on in the process of getting and displaying the answers. I will be making a mod soon that will be added on to this and it will email the forms to a selected email address so that they are sent to something to be reviewed by a person... you know what I mean? Also if you want a demo, I have one set up on my website: Demo: CLICK HERE If you need any help or some more understanding of the script then just ask by reply ing to this post. Enjoy! |
|
|
|
Mar 19 2005, 06:19 AM
Post
#2
|
|
|
Administrator ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 377 Joined: 28-December 04 From: USA Member No.: 2,992 |
Nice demo on your site, good job.
Nils |
|
|
|
Mar 19 2005, 06:53 PM
Post
#3
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 380 Joined: 22-December 04 From: usa Member No.: 2,873 |
Hi maddog39,
Very nice idea/ implementation. Can't wait to see the e-mail forwarding function/ mod. Been looking for something like this for a while. How would you go about making this an exit questionaire(pop up etc.) for your website when visitors leave? RGPHNX |
|
|
|
Mar 19 2005, 07:19 PM
Post
#4
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 208 Joined: 27-January 05 From: LI, New York Member No.: 3,448 |
I would probabl put some Javascripts to do it in my front page and then insert sessions into the pages so it knows when to do it and to see if the person already saw the quiz, things like that.
|
|
|
|
Mar 19 2005, 09:12 PM
Post
#5
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 287 Joined: 23-February 05 Member No.: 3,945 |
Woah, that's really good, nice job! You should try adding a answer scrambler where it mixes up the answers so multiple answer questions will have diferent letters each time.
|
|
|
|
Mar 19 2005, 10:43 PM
Post
#6
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 208 Joined: 27-January 05 From: LI, New York Member No.: 3,448 |
I think thats a little hard. That would be easier with flash or something prolly. I am still learning php and I can do all this stuff lol. Anyway thanks for all the completments. I should have that mod by tomorrow because im kinda busy today.
|
|
|
|
Mar 23 2005, 12:07 AM
Post
#7
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 208 Joined: 27-January 05 From: LI, New York Member No.: 3,448 |
Okay guys. Im sorry it took so long ive just been kinda really busy. Anyway here it is with the email mod. All you have to do is open up results.php, erase the hole entire thing and paste in this new code. I had to kinda mod the hole thing so its just easier to do it this way. So heres the code.
CODE <?php $title = "Quiz Results"; echo "<title>$title</title>"; if (isset ($_POST['submit'])) { $name = $_POST['name']; $q1 = "1.)" . $_POST['q1']; $q2 = "2.)" . $_POST['q2']; $q3 = "3.)" . $_POST['q3']; $q4 = "4.)" . $_POST['q4']; $q5 = "5.)" . $_POST['q5']; $qp = "6.)" . $_POST['qp']; } if ($name == "") { die ("You forgot something, go back and check over your quiz."); } if ($q1 == "1.) ") { die ("You forgot something, go back and check over your quiz."); } if ($q2 == "2.) ") { die ("You forgot something, go back and check over your quiz."); } if ($q3 == "3.) ") { die ("You forgot something, go back and check over your quiz."); } if ($q4 == "4.) ") { die ("You forgot something, go back and check over your quiz."); } if ($q5 == "4.) ") { die ("You forgot something, go back and check over your quiz."); } { echo<<<EOT <p>Results: $name<br> $q1<br> $q2<br> $q3<br> $q4<br> $q5</p> <p><a href="$qp">Go Back To Quiz?</a> EOT; } $Name = $_POST['name']; $Subject = "Quiz Results"; $Email = "You@mail.com"; $Message = "Here are the quiz results."; $align = $_POST['align']; $to = "$EmailTo"; $subject = "$Subject"; $body = "$Message\n\nQuiz By: $Name\n$q1\n$q2\n$q3\n$q4\n$q5"; mail($to,$subject,$body); header("Location: sent.htm"); ?> and change the things you need to change. You will need to change the '$Email' variable to your email address inside the quotes and you will also need to make another page called sent.htm which would probably look something like this... CODE <html> <head> <title>Message Sent</title> </head> <body> <p>Your quiz has been sent to the webmaster. You should recieve a reply shortly. </p> <p><a href="http://yoursite.trap17.com/index.php" target="_self">Go Back To Index?</a></p> </body> </html> which will tell the person that there quiz was sent. Also change'yoursite' yo your actual website URL so that they may go back to you homepage. |
|
|
|
Mar 23 2005, 12:56 AM
Post
#8
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 51 Joined: 22-March 05 Member No.: 4,813 |
I did a little improving on the results.php page:
CODE // Below gets the answers from the page before and checks to see if you forgot anything
while (extract($_POST) == '' && isset($_POST['submit'])) { die("You forgot something, go back and check over your quiz."); } // make some valid html with newlines echo "<html>\n<head>\n<title>\nQuiz Results\n</title>\n</head>\n<body>\n"; echo "Results: $name<br />\n"; for ($i = 1; $i <= 5; $i++) { echo "$i.) ${q . $i}<br />\n"; } echo '<a href="' . $qp . '">Go Back To Quiz?</a><br />'; echo "\n</body>\n</html>"; |