🔒 Closed Session post and Get method

Status
Not open for further replies.

m0stwanted143

Eternal Poster
Code:
<?php 
session_start();
include("./config/db_connect.php"); 
include("templates/sidebar.php"); ?>
<?php include("header.php"); 
echo"<div>";
$score = 0;
$total == $_SESSION[$score];
$que_no = $_GET['question_no'];
$result=mysqli_query($conn, "SELECT * FROM `exam_questions` where question_no=$que_no");
echo "<form method = "POST">";
echo"<table>";
if($row=mysqli_fetch_array($result)){
    
    
    echo"<tr>";
    echo"<td>".$row['question_no'].")".$row['question']."</td>";
    echo"</tr>";
    echo"<tr>";
    echo"<td>";
    echo"<input type='radio' id='option1' name='option' class='radoptions' value=".$row['opt1']." />".$row['opt1']."<br>";
    echo"<input type='radio' id='option2' name='option' class='radoptions' value=".$row['opt2']." />".$row['opt2']."<br>";
    echo"<input type='radio' id='option3' name='option' class='radoptions' value=".$row['opt3']." />".$row['opt3']."<br>";
    echo"<input type='radio' id='option4' name='option' class='radoptions' value=".$row['opt4']." />".$row['opt4']."<br>";
    echo"</td>";
    echo" </li>";
    echo "<br/>";
    echo"</tr>";
    echo "</tr>";
    echo "</table>";
    echo "</div>";
    if(isset($_POST['option']))
        {
            $option = $_POST['option'];
        }
        else{
            $option = NULL;
        }
        if($option != NULL){
            if($option != $answer['answer']){
                
            }
            else{
                echo $score++;
            }
        }
        else{
            echo "You must select an answer";
        }
}
?>
<?php
$next = mysqli_query($conn, "SELECT * FROM exam_questions WHERE question_no>$que_no order by question_no ASC ");
$sql = "SELECT COUNT(question_no) AS total FROM exam_questions WHERE examname='quizko'";
$result=mysqli_query($conn,$sql);
$values=mysqli_fetch_assoc($result);
$num_rows=$values['total'];
echo "<center><br/><br/><br/>";
echo "Question $que_no of $num_rows";
if($row = mysqli_fetch_array($next)){
    
    
    echo ' <a href="next.php?question_no='.$row['question_no'].'"><button type="button"> Next</button></a>';
     
    echo "</center>";
}
if($que_no == $num_rows)
{
    echo ' <a href="next.php?question_no='.$row['question_no'].'"><button type="button"> submit</button></a>';
}
echo "</form>";
    
    



?>
Pa help po ayaw po kasi gumana nung session gusto ko sana yung score nag iincrement pag tumama yung sagot nya sa radio button
then pag na change ung page yun pa rin yung score nya once na hindi nag sasagot then increment ulit.. I hope na matulungan nyu ko..

Sainyo nalang ako umaasa kasi mga kaklase ko di ako tinutulungan halos thesis namin ako lang gumagawa :(
 
Hi sir, I advise you put your code somewhere online so that we can simulate it and find the errors:

But based on visual inspection. you should store Session of score. On line 44 of your code add in the next line:
PHP:
$_SESSION["score"] = VALUE_OF_THE_SCORE_HERE;
or
$_SESSION["score"] = $score;

To retrieve the score in session:
PHP:
what_is_the_current_score = $_SESSION["score"];

Also, in line 7, every restart of the page the score will always set the score to zero. So instead setting it to zero. Do a check if $_SESSION['score'] exist:
PHP:
if (isset($_SESSION['score'])){
    score = $_SESSION["score"];
}
else {
    score =0;
}


Don't forget to set $_SESSION["score"] = 0; after the test is done
 
Wag mo kasi palitan session name

Value lang palaitan mo

Bale

$_SESSION['score'] = 0;

Yan sa una

Pag mag increment ka ganto

$prevscore = $_SESSION['score'];
$newScore = $prevscore + 1;
$_SESSION['score'] = $newScore;
 
Salamat . Update kita kung anu pa error. Salamat tlga wala tlga akong mahanap na makakatulong. Halos self study ako tapos mabagal pa internet namin. Kaya nahihirapan ako.
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 779
    Views
  • 3
    Participants
Last reply from:
m0stwanted143

Trending Topics

Online now

Members online
842
Guests online
852
Total visitors
1,694

Forum statistics

Threads
2,273,625
Posts
28,950,742
Members
1,234,889
Latest member
ang sher
Back
Top