Hi,

to my understanding, isset() checks is the variable exist and have a value. But when I try the code below, _randNum() keeps on getting new values when it should already have a value because it already exist and have a value.

<?php
    session_start();
    if(!isset($_randNum)){ //Check if the variable dont exist 
        $_randNum = rand (10, 20); //if not
    }
    $rNum = $_randNum;
?>

I have a form to check the value in $rNUm:

    <form method="post" action="guessinggame.php">
        <p><input type="text" name="tb" id="tb" />
        <input type="submit" name="guess" id="guess" value="Guess" /></p>
    </form>
    <?php
        echo "$rNum";
    ?>

This is my first php so i'm not really sure whats going on.

Although you are setting a session you aren't putting anything into, or passing values via the form.
This means that on each page reload $_randNum isn't set as the page is 'new' and has no variables being passed to it or being retrieved from the session.
To add the rand number to the session:
$_SESSION['rand'] = $_randNum;
To retrieve:
if(!isset($_SESSION['rand']))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.