minor error

Discussion in 'PHP' started by demons-halo, Sep 24, 2009.

  1. #1
    i keep getting this error

    Parse error: syntax error, unexpected $end in /public_html/test2.php on line 16

    whats up with this code??

    <?php
    include "globals.php";
    {
    $price=($ir['hp']);
    $chest=($ir['maxhp']);
    $main=($chest - $price);
    if($fm < $main)
    echo "You can't afford to heal yourself";
    else
    $db->query("UPDATE users SET money=money-$main WHERE userid=$userid");
    $query3="UPDATE users SET hp=hp+(maxhp/3) WHERE hp<maxhp";
    $query4="UPDATE users SET hp=maxhp WHERE hp>maxhp";
    $db->query($query3);
    $db->query($query4);
    print "You healed yourself";
    ?>
    PHP:

    dont worry about the variable $fm thats being called in from globals.php
     
    Last edited: Sep 24, 2009
    demons-halo, Sep 24, 2009 IP
  2. superdav42

    superdav42 Active Member

    Messages:
    125
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #2
    You have an open brace '{' on line 2 but no closing brace. You probably also want to put braces '{}' around the lines after the else, otherwise it will just execute the first line as the else and the rest will always be executed.
     
    superdav42, Sep 24, 2009 IP
  3. newgenservices

    newgenservices Well-Known Member

    Messages:
    862
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    105
    Digital Goods:
    1
    #3
    Replace your code with

    
    <?php
    include "globals.php";
    
    $main= $ir['maxhp'] - $ir['hp'];
    
    if($fm < $main){
    	echo "You can't afford to heal yourself";
    } else {
    	$db->query("UPDATE `users` SET money=money-".$main." WHERE userid=".$userid);
    	$db->query("UPDATE `users` SET hp=hp+(maxhp/3) WHERE hp<maxhp");
    	$db->query("UPDATE `users` SET hp=maxhp WHERE hp>maxhp");
    	echo "You healed yourself";
    }	
    ?>
    
    Code (markup):
    and it should work :) I assume $userid is also available from globals.php
     
    newgenservices, Sep 25, 2009 IP
  4. demons-halo

    demons-halo Active Member

    Messages:
    243
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #4
    @newgenservices hey buddy, thanks for your coding help, it really helped me loads !! cheers :D :D :D :D
     
    demons-halo, Sep 25, 2009 IP
  5. newgenservices

    newgenservices Well-Known Member

    Messages:
    862
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    105
    Digital Goods:
    1
    #5
    You are welcome :)
     
    newgenservices, Sep 25, 2009 IP