简体   繁体   中英

Passing Javascript Variables to a PHP Server

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.

错误与提交按钮有关,它被设置为type =“ button”而不是type =“ submit”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM