Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6784891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:03:22+00:00 2026-05-26T17:03:22+00:00

I’m trying to make a simple three question quiz in php. After the user

  • 0

I’m trying to make a simple three question quiz in php. After the user signs in, they begin the quiz and have 15 minutes to complete it (I have the session part figured out). One true/false, one multiple choice and one short answer. Each question appears separately on each page.

My question is whether my logic is right so far. This program will not run due to several syntax errors. It tells me to delete brackets when they should be there. For example, in line 55, it tells me I should delete the last }

  if ($selected_radio == 'false') {
  correct()
  }

Could someone look over this and give me some pointers on where to go? If I’m completely off track, please let me know how I should move forward. Examples would be great.

I appreciate your time. Since this is rather long, I uploaded the code here: http://paste.bradleygill.com/index.php?paste_id=339313

My code:

<?php
ini_set('session.gc_maxlifetime',900);
ini_set('session.gc_probability',1);
ini_set('session.gc_divisor',1);
//echo ini_get("session.gc_maxlifetime"); 
session_start();
if($_SESSION['loggedin'] !== 1) {
header('Location: login.php');
exit;
}

if (!session_is_registered("number"))
{
$_SESSION["number"] = 0;
$_SESSION["answer"] = 0;
$_SESSION["correct"] = 0;
}

$total_number = 3;

print <<<TOP
<html>
<head>
<title> History Quiz </title>
</head>
<body>
<h3> History Quiz </h3>
TOP;

$number = $_SESSION["number"];
$answer = $_SESSION["answer"];
$correct = $_SESSION["correct"];


if ($number == 0){
$answer = "false";
$_SESSION["answer"] = $answer;
 print <<<FIRST
 <p> You will be given $total_number questions in this quiz. <br /><br/>
  You will have 15 minutes to complete it. <br /><br/>
  You cannot go back to change previous answers.<br /><br/>
  Here is your first question: <br /><br />
 </p>
 <p>1. Abe Lincoln was born in Illinois.</p>
 <p>
    <label><input type="radio" name="question1" value="true" /> True </label>
    <label><input type="radio" name="question1" value="false" /> False </label>
</p>
FIRST;

if (isset($_POST['submit'])) {

$selected_radio = $_POST['question1'];

if ($selected_radio == 'false') {
   correct()
}
else {
   wrong();
}
}
}


if ($number == 1){
$answer = "Pennsylvania";
$_SESSION["answer"] = $answer;
print <<<SECOND
<p>2. In what state was the battle of Gettysburg fought?</p>
<p>
    <label><input type="checkbox" name="question2" value="Texas" /> a) Texas </label><br/>
    <label><input type="checkbox" name="question2" value="Pennsylvania" /> b) Pennsylvania   
</label><br/>
    <label><input type="checkbox" name="question2" value="Virginia" /> c) Virginia </label><br/>
    <label><input type="checkbox" name="question2" value="West Virginia" /> d) West Virginia     

</label>
</p>
SECOND;

if (isset($_POST['submit'])) {

$selected_checkbox = $_POST['question2'];

if ($selected_checkbox = = 'Pennslyvania') {
   correct($correct)
}
else {
   wrong($answer);
}
}


if ($number == 2){
$answer = "lee";
$_SESSION["answer"] = $answer;
print <<<THIRD
<p>5. The last name of the commander of the Army of North Virginia was __________.</p>
<p>
    <input type='text' id='question3' />
THIRD;

if (isset($_POST['submit'])) {

$selected_answer = $_POST['question3'];

if ($selected_answer = = 'lee') {
   correct($correct)
}
else {
   wrong($answer);
WRONG;
}
}
}



function correct($correct) {
$correct++;
$_SESSION["correct"] = $correct;
return $correct;
print <<<CORRECT
  You are correct!  Good Job!
  <br /><br />
CORRECT;
 }

function wrong($answer) {
print <<<WRONG
  Sorry, the correct answer is: $answer.
  <br /><br />
WRONG;

}


if ($number >= $total_number)
{
print <<<FINAL_SCORE
Your final score is $correct correct out of $total_number. <br /><br />
Thank you for playing. <br /><br />
FINAL_SCORE;
session_destroy();
}
else
{
$number++;
$_SESSION["number"] = $number;
$script = $_SERVER['PHP_SELF'];
print <<<FORM
<form method = "post" action = $script>
$question
<input type = "text" name = "answer" value = "" size = "5" />
<input type = "submit" value = "Check Answer" />
</form>
 FORM;
 }

print <<<BOTTOM
</body>
</html>
BOTTOM;
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:03:23+00:00Added an answer on May 26, 2026 at 5:03 pm

    No, this isn’t doing it right. Honestly, there’s too much going on here to even really critique. Posting a smaller sample would be easier.

    A few things jump out at me:

    1. Repetitive code – look to factor this out in to functions
    2. Logic, data, and HTML are all intermingled. This is not good.

    it’s code like this that people point to when they laugh at PHP. Sorry if that sounds harsh, but it’s true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.