Jump to content

Search the Community

Showing results for tags 'multiple choice quiz'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. I'm working on a project that users can enter their name to complete a multiple choice quiz, while administrators can log in to add new questions and edit and delete existing questions. I've created a multiple choice quiz in PHP and MySQL that loops questions on the same page, instead of multiple pages. Basically, you click on the submit button to go to the next set of questions, but on the same page. The questions are data retrieved from a database I created in PhpMyAdmin. The problem now is I have no idea what code to refer to when trying to calculate answers in the final results page, so I was wondering if someone could help me out. Underneath is the code I have for my quiz.php page, and now I want to calculate how many questions I have answered correctly. I'd really appreciate the help. <?php //CODE FOR QUIZ.PHP //Code retrieves the name that the user typed in the text-field. session_start(); require 'includes/connection.php'; $name = $_REQUEST['name']; $_SESSION['name'] = $name; //User's name is displayed above the quiz. echo 'Welcome, '.$name; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>World War II Quiz</title> </head> <body> <?php //Start with question ID if (isset($_GET['id'])) { //get question id from user and store $question_id = $_GET['id']; } else { $question_id = 1; //no question id submitted //unset session data unset($_SESSION['questions']); unset($_SESSION['total']); } //If the questions array has been built if (isset($_SESSION['questions'])) { //has the user selected a radio button if (isset($_REQUEST['value'])) { //check for correct if ($_SESSION['answer'] == $_REQUEST['value']) { //correct answer $_SESSION['total']++; } } else { //No value inputted from the user echo "hey bozo click a button"; $question_id--; } } //Questions array is not been built else { //get a list of question id's $sql = "SELECT question_id FROM questions ORDER BY question_id ASC"; $results = mysql_query($sql,$conn); $stringtemp = ""; $maxtemp = 1; while ($row = mysql_fetch_assoc($results)) //More results { $stringtemp = $stringtemp." ".$row['question_id']; $maxtemp++; } //Create question id array pulled from database $_SESSION['questions'] = explode(" ",$stringtemp); //Max value of the array $_SESSION['max']=$maxtemp; } $sql = "select * from questions where question_id =".$_SESSION['questions'][$question_id]; $results = mysql_query($sql,$conn); $row = mysql_fetch_array($results); //Store correct answer for next pageload $_SESSION['answer'] = $row['correct']; $nextid=$question_id+1; if ($nextid == $_SESSION['max']) { //Final question $next = "results.php"; } else { $_SESSION['name'] = $name; //Not the final question $next = "quiz.php?id=".$nextid; } echo "<form action=\"".$next."\" method=\"post\" name=\"form\" > <p>".$row['question_text']."</p> <input type=\"radio\" name=\"value\" value=\"1\">".$row['answer1']."<br> <input type=\"radio\" name=\"value\" value=\"2\">".$row['answer2']."<br> <input type=\"radio\" name=\"value\" value=\"3\">".$row['answer3']."<br> <input type=\"radio\" name=\"value\" value=\"4\">".$row['answer4']."<br> <input class=\"submit\" type=\"submit\" value=\"Submit\"/> </form> </body> </html> "; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.