0

I'm having some real difficulty with this, I've been searching for hours and hours and I'm having trouble understand. I know there are other questions like this but I think I need some context help.

The aim is: Everytime a user attempts a quiz, the score they receive will be recorded as a separate record in the attempts table.

I have the following pages:

quiz_form.php, quiz_process.php and quiz.js

The score that I need to pass through to the php, is calculated in the JS file, passed through HTML in results.php and displayed. I need to get this variable, somehow into quiz_process and put it into a table.

Quiz_form.php:

<form id="quiz" method="get" class="detailsform" novalidate="novalidate" action="quiz_process.php">

****** QUESTION CODE HERE *****

    <input class="button" type="button" id="chkans" value="Check Answers" />
    <input class="button" type="button" id="submit" value="Submit" />
    <input class="button" type="reset" value="Reset"/>
</form>

quiz.js

function sumbit_answers()
{
    store_answers();
    sessionStorage.result = mark_answers();
    alert(sessionStorage.result);
    document.getElementById("result").value = sessionStorage.result;

    alert("You have finished the quiz. Please click OK to go to the results page.");
    window.location.href="quiz_process.php";
}

quiz_process.php

<?php
require_once("settings.php");

session_start();
$email = $_SESSION["email"];
$result = $_GET["result"];
echo $email; echo $result;

?>

Email is getting through and it's showing but result seems to be very hesitant. Thank you for any help, I'm sorry for posting but it's 3AM and it's doing my head in.

8
  • can you tell where you call that function of quiz.js? Commented May 24, 2015 at 17:23
  • 1
    Insert a hidden input with the value of the score before submit is executed. delete window.location.href="quiz_process.php";. Commented May 24, 2015 at 17:24
  • I call that function after the button click of submit of the form Commented May 24, 2015 at 17:25
  • @rookie - Been trying that, think it executes too late or I'm naming it wrong. EDIT: Giving it another go now. Only thing is, last time I did that, it didn't submit it to Quiz_process Commented May 24, 2015 at 17:26
  • where do you call sumbit_answers()? typo? Commented May 24, 2015 at 17:34

1 Answer 1

1

The error was with the submit button, it was set to type="button" not type="submit".

Sign up to request clarification or add additional context in comments.

1 Comment

I find a quick nap or a short walk helps with code blindness ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.