John Davidson

php - Data is still kept and won't restart back from zero

0 comments
Message:


I have a quiz system where if the correct answer is chosen, the score will +1. But I clicked backspace once, and the score won't reset to 0 everytime I backspace. I tried re-answering the question, but the score is still kept and won't start back from 0


keep in mind tho i used 'skor' instead of 'score'


<?php
require 'connect.php';
//GET SUBJECT ID
session_start();
$topikpilihan=$_SESSION['topikpilihan'];
?>
<?php session_start(); ?>


//CHECK SCORE
<?php
if (!isset($_SESSION['skor'])){
$_SESSION['skor'] = 0;
}

//WHEN THE SELECTED ANSWER IS POSTED
if($_POST){
$idsoalan = $_POST['idsoalan'];
$number = $_POST['number'];
$selected_choice = $_POST['pilihan'];
$nextsoalan=$number+1;
$totalsoalan=4;

//GET TOTAL QUESTIONS
$query="SELECT * FROM soalan where idtopik= '$topikpilihan'";
$result1 = mysqli_query($condb,$query);
$totalsoalan=mysqli_num_rows($result1);

//GET CORRECT ANSWER
$query2 = "SELECT * FROM soalan WHERE nosoalan = $number AND idsoalan=$idsoalan";
$result2 = mysqli_query($condb,$query2);
$row = mysqli_fetch_assoc($result2);
$correct_choice=$row['jawapansoalan'];

//COMPARE SELECTED ANSWER AND CORRECT ANSWER
if($correct_choice == $selected_choice){
$semakan="TEPAT";
$_SESSION['skor']++;
}
if($number == $totalsoalan){
header("Location: jawabsoalan-tamat.php");
exit();
} else {
header("Location: jawabsoalan-mula.php?semakan=".$semakan."&idtopik=".$topikpilihan."&n=".$nextsoalan."&skor=".
$_SESSION['skor']);
}
}
?>


My Answer:
t be lost even if the page is refreshed or the user navigates away from the page. This is because PHP is a server-side language, meaning that the data is stored on the server and not on the user's device. This allows for persistent data storage and retrieval, ensuring that the information remains accessible throughout the user's session.

Rate this post

5 of 5 based on 9051 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us