Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    My php code doesnt work, can anbody solve or revise this code please?

    the code is for a number guessing game
    the user should be given 7 attempts then the game resets.
    a running total of numbers should also be displayed
    the error i get is

    Parse error: syntax error, unexpected '=', expecting ',' or ')' in F:\EasyPHP-12.1\www\scripting\guessinggame.php on line 1

    the code i used is

    <code>

    <?php
    if(isset($_POST['guess'])){if(!isset($_SESSION['life']=1);
    else if($_SESSION['life']==7){
    echo "Your Life end<br>Thanks for playing<br>";
    unset($_SESSION['life']);
    }
    else
    $_SESSION['life']++;
    $guess=intval($_POST['guess']);
    $secret=rand(1,10);
    if($guess==$secret){
    $output="<h1>Correct!</h1>";
    $output .="<a href='guessinggame.php'>Play again</a>";
    unset($_SESSION['life']);
    }
    elseif($guess<$secret){
    $output.="<h1>Your answer was too low. Please try again!";
    }
    else{
    $output.="<h2>Your answer was too high. Please try again!</h2>";
    }
    }
    ?>


    <code>

    any ideas?
    thanks so much

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    722
    Thanks
    20
    Thanked 84 Times in 84 Posts
    PHP Code:
    if(!isset($_SESSION['life']=1
    should be
    PHP Code:
    if(!isset($_SESSION['life'])) 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •