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

  • Home
  • SEARCH
  • 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 8949953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:20:22+00:00 2026-06-15T13:20:22+00:00

I’ve tried numerous things to make this functionality work. I’ve searched all over stackoverflow

  • 0

I’ve tried numerous things to make this functionality work. I’ve searched all over stackoverflow to see if there was a solution for the particular issue that I’m having and I’m getting no where. I was wanting to reset the session variable to have the value of 0 when the user hit’s the reset button, which is simply just a submit button. I’ve tried changing it to a get and then setting the if statement to pull from the server to see if the request is GET. I did the same with POST and had no luck. The session just remains and won’t destroy at all. It’s like it’s just neglecting the if statement because I’ve tried doing a test with an echo statement and get nothing in response. Any ideas of what might be causing the issue? I am populating the session variable then setting it to a variable called $db_value. The reason I did that is so that I can write the result to the database and then pull again from the database when the user continues playing.

<?php session_start();
    $host = "localhost";
    $user = "username here";
    $pass = "";
    mysql_connect($host, $user, $pass) or die(mysql_error());
    mysql_select_db("RPS") or die(mysql_error());
    mysql_query("SET SQL_SAFE_UPDATES=0;"); // allows updating of table
    mysql_query("Create table if not exists RPS (score int);");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Rock, Paper, scissors</title>
</head>
<body>

</body>
</html>

<?php
if (isset($_SESSION['Score'])) {
if ($_POST['user_choice']) {
    $user_choice = $_POST['user_choice'];

    $Choosefrom = array(Rock, Paper, Scissors);
    $Choice = rand(0, 2);
    $Computer = $Choosefrom[$Choice];


    //create a variable for the database to use
    $q = mysql_query("SELECT * FROM RPS;");
    $db_array = mysql_fetch_array($q);
    $db_value = $db_array[0];

    if ($user_choice == $Computer) {
        echo 'Result : Draw +0';
        $_SESSION['Score'] = (int) $_SESSION['Score'];
        $db_value = $_SESSION['Score'];
        mysql_query("UPDATE RPS SET score=$db_value;");
    } else if ($user_choice == 'Rock' && $Computer == 'Scissors') {
        echo 'Result : Win +1';
        $_SESSION['Score'] = (int) $_SESSION['Score'] + 1;
        $db_value = $_SESSION['Score'];
        mysql_query("UPDATE RPS SET score=$db_value;");
    } else if ($user_choice == 'Rock' && $Computer == 'Paper') {
        echo 'Result : Lose -1';
        $_SESSION['Score'] = (int) $_SESSION['Score'] - 1;
        $db_value = $_SESSION['Score'];
        mysql_query("UPDATE RPS SET score=$db_value;");
    } else if ($user_choice == 'Scissors' && $Computer == 'Rock') {
        echo 'Result : Lose -1';
        $_SESSION['Score'] = (int) $_SESSION['Score'] - 1;
        $db_value = $_SESSION['Score'];
        mysql_query("UPDATE RPS SET score=$db_value;");
    } else if ($user_choice == 'Scissors' && $Computer == 'Paper') {
        echo 'Result : Win +1';
        $_SESSION['Score'] = (int) $_SESSION['Score'] + 1;
        $db_value = $_SESSION['Score'];
        mysql_query("UPDATE RPS SET score=$db_value;");
    } else if ($user_choice == 'Paper' && $Computer == 'Rock') {
        echo 'Result : Win +1';
        $_SESSION['Score'] = (int) $_SESSION['Score'] + 1;
        $db_value = $_SESSION['Score'];
        mysql_query("UPDATE RPS SET score=$db_value;");
    } else if ($user_choice == 'Paper' && $Computer == 'Scissors') {
        echo 'Result : Lose -1';
        $_SESSION['Score'] = (int) $_SESSION['Score'] - 1;
        $db_value = $_SESSION['Score'];
        mysql_query("UPDATE RPS SET score=$db_value;");
    }

    echo ' You\'re score is currently: ' . $_SESSION['Score'];
    echo '<a href="rps.php">Play Again ?</a>';
    echo '<form method="POST" action="rps.php"><input type="hidden" name="hidden" /><input type="submit" value ="Reset" name="reset" /></form>';
    if ($_POST['reset']) {
        $_SESSION['Score'] = 0;
        $db_value = $_SESSION['Score'];
        unset($_SESSION['Score']);
        session_start();
        session_destroy();
        mysql_query("UPDATE RPS SET score=$db_value;");
        header('Location:rps.php');
    }
} else if (!$_POST['user_choice']) {
    echo 'Your Current Score is: ' . $_SESSION['Score'] . '<form action="rps.php" method="post" />
     <input type="image" src="images/Rock.png" alt="Rock" name="user_choice" value="Rock" title="Rock" height="115" /> <br /><br />
      <input type="image" src="images/Paper.png" alt="Paper" name="user_choice" value="Paper" title="Paper" height="115"/> <br /><br />
       <input type="image" src="images/Scissors.png" alt="Scissors" name="user_choice" value="Scissors" title="Scissors" height="115"/> <br /><br />
   </form> ';
     }
 } else if (!isset($_SESSION['Score'])) {
      $_SESSION['Score'] = 0;

   echo 'Your Current Score is: ' . $_SESSION['Score'] . '<form action="rps.php" method="post" />
  <input type="image" src="images/Rock.png" alt="Rock" name="user_choice" value="Rock" title="Rock" height="115" /> <br /><br />
  <input type="image" src="images/Paper.png" alt="Paper" name="user_choice" value="Paper" title="Paper" height="115"/> <br /><br />
   <input type="image" src="images/Scissors.png" alt="Scissors" name="user_choice" value="Scissors" title="Scissors" height="115"/> <br /><br />
      </form>';
            }
           ?>
             echo'<form method="POST" action="">
             <input type="hidden" name="hidden" />
             <input type="submit" value ="Reset" name="reset" />
            </form>';
             if (isset($_POST['reset']) && ($_POST['reset'] == "Reset")) {
             $_SESSION['Score'] = 0;
            $db_value = $_SESSION['Score'];
           unset($_SESSION['Score']);
            session_start();
          session_destroy();
          mysql_query("UPDATE RPS SET score=$db_value;");
           header('Location:rps.php');
         }
  • 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-06-15T13:20:23+00:00Added an answer on June 15, 2026 at 1:20 pm

    You might try $_REQUEST[‘Reset’] instead of get or post to cover your bases. Use the following sequence at the very top of your code only to destroy a session…

    $session_id = session_id();
    
    if(empty($session_id)){
     session_start();
    }
    
    if(isset($_REQUEST['Reset'])){
     session_unset();
     session_destroy();
     $_SESSION = array();
     session_start();
     session_regenerate_id();
    }
    

    by and by, your form is way wrong. I doubt you’re even getting data from the values here. change it to this:

    echo ' You\'re score is currently: ' . $_SESSION['Score'];
    echo '<form method="POST" action="rps.php"><input type="hidden" name="hidden" /><input type="submit" value ="Play Again" name="Reset" /></form>';
    

    …

    then on the top of the page do what i put plus a little of yours…

    $session_id = session_id();
    
    if(empty($session_id)){
     session_start();
    }
    
    if(isset($_REQUEST['Reset'])){
     $_SESSION['Score'] = 0;
     $db_value = $_SESSION['Score'];
     session_unset();
     session_destroy();
     $_SESSION = array();
     session_start();
     session_regenerate_id();
    
     mysql_query("UPDATE RPS SET score = $db_value WHERE unique_field = $unique_field");
     header('Location:rps.php');
     exit;
    }
    

    where you use this:

    if ($_POST['reset']) {
    

    that will always return true if you write it without a condition. for the value. Plus PHP is case sensitive, so use Reset if you do it how I wrote it.

    You’re not using XHTML validation, you’re using HTML 4.01 Transitional so don’t do this:

    <br />
    

    do this:

    <br>
    

    also that goes for the / on your images as well.

    Final thought, use a unique value when doing your update, because your statement will change every record in the entire table. See my example with the WHERE clause.

    • 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'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.