Probably a simple Fix I cant see

Discussion in 'PHP' started by Raynard82, May 11, 2009.

  1. #1
    This is probably a simple fix but ive been staring at it for so long i cant see it this is the error im getting Parse error: syntax error, unexpected $end in /home/tgf123/public_html/loanofficer.php on line 91

    <?php
    /*
    mod made by Twysted
    */
    session_start();
    require "globals.php";
    print "<h3>Loan Officer</h3>
    <br />
    Welcome to the Loan Officer!";
    if($ir['level']>=10 || $ir['user_level'] == 1)
    {
    if($ir['loan_days'] == $ir['loan_days_max'])
    {
     print "You have had your bank account frozen. and you have lost your house.<br/>
     From now on until your loan balance is paid fully you will not recieve any money for your efforts.";
     $db->query("UPDATE users SET bank_frozen=1,lose_house=1 WHERE userid=$userid");
     exit;
    }
    else
    {	
    switch($_GET['action'])
    {
    case "deposit":
    deposit();
    break;
    
    case "withdraw":
    withdraw();
    break;
    
    default:
    index();
    break;
    }
    
    function index()
    {
    global $ir,$db,$userid,$h;
    $loanleft = $ir['maxloan']-$ir['loan']+$ir['loanintrest'];
    print "\n<b>Your maxloan is \${$ir['maxloan']}. Your current loan is \${$ir['loan']}.</b><br />
    At the end of each day, 10% of your loan amount will be taken away from your on-hand cash until you repay your loan.<br />
    <table width='75%' border='2'> <tr> <td width='50%'><b>Pay Back Money</b><br />
    <form action='loanofficer.php?action=deposit' method='post'>
    Amount: <input type='text' name='deposit' value='{$ir['loan']}' /><br />
    <input type='submit' value='Pay Back' /></form></td> <td>
    <b>Take money</b><br />
    <form action='loanofficer.php?action=withdraw' method='post'>
    Amount: <input type='text' name='withdraw' value='$loanleft' /><br />
    <input type='submit' value='Take Out' /></form></td> </tr> </table>";
    }
    
    function deposit()
    {
    global $ir,$db,$userid,$h;
    $_POST['deposit']=abs((int) $_POST['deposit']);
    if($_POST['deposit'] > $ir['money'])
    {
    print "You do not have enough money to deposit this amount.";
    }
    else
    {
    $gain=$_POST['deposit'];
    $ir['loan']-=$gain;
    mysql_query("UPDATE users SET loan=loan-$gain, money=money-{$_POST['deposit']} where userid=$userid",$db);
    print "You hand over \${$_POST['deposit']} to be paid for your loan, <br />
    <b>You now have a loan of \${$ir['loan']} taken out.</b><br />
    <a href='loanofficer.php'>&gt; Back</a>";
    }
    }
    function withdraw()
    {
    global $ir,$db,$userid,$h;
    $_POST['withdraw']=abs((int) $_POST['withdraw']);
    $loanleftstill = $ir['maxloan'] - $ir['loan'];
    if($_POST['withdraw'] > $loanleftstill)
    {
    print "You don't have enough money left in your max loan to withdraw this amount, choose a different amount or upgrade your max loan.";
    }
    else
    {
    
    $gain=$_POST['withdraw'];
    $ir['loan']+=$gain;
    mysql_query("UPDATE users SET loan=loan+$gain, money=money+$gain where userid=$userid",$db);
    print "You ask for and get a loan of $gain, <br />
    <b>You now have a loan of \${$ir['loan']} taken out.</b><br />
    <a href='loanofficer.php'>&gt; Back</a>";
    }
    }
    $h->endpage();
    ?>   
    Code (markup):
    Any Help would be seriuosly appreciated
     
    Raynard82, May 11, 2009 IP
  2. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
       else
        {	
            switch($_GET['action'])
            {
                case "deposit":
                deposit();
                break;
    
                case "withdraw":
                withdraw();
                break;
    
                default:
                index();
                break;
            }
    <------- Forgot a } here
    function index()
    
    PHP:
    PS: you don't really need break after the default: selection since its the last one in the list.
     
    kblessinggr, May 11, 2009 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    You probably are missing a closing bracket }...

    I think you are missing one after:
    default:
    index();
    break;
    }

    Should be:
    default:
    index();
    break;
    }}
     
    jestep, May 11, 2009 IP
  4. Raynard82

    Raynard82 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    still getting error at line 91 unexpected end of file
     
    Raynard82, May 11, 2009 IP
  5. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You also forgot a } here

    
       session_start();
        require "globals.php";
        print "<h3>Loan Officer</h3><br />Welcome to the Loan Officer!";
        if($ir['level']>=10 || $ir['user_level'] == 1)
        {
            if($ir['loan_days'] == $ir['loan_days_max'])
            {
                print "You have had your bank account frozen. and you have lost your house.<br/>From now on until your loan balance is paid fully you will not recieve any money for your efforts.";
                $db->query("UPDATE users SET bank_frozen=1,lose_house=1 WHERE userid=$userid");
                exit;
            }
        } <-------------
        else
        {	
    
    PHP:
    Tab out your code in the future, and put functions at the top of the PHP, it'll help find little errors like that in the future. (since functions only run when called, its not going to hurt you having the functions listed above your session and other lines. )
     
    kblessinggr, May 11, 2009 IP
  6. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Full code rewrite with the two braces put in:

    
    <?php
        
    function index()
    {
        global $ir,$db,$userid,$h;
        $loanleft = $ir['maxloan']-$ir['loan']+$ir['loanintrest'];
        echo "\n<b>Your maxloan is \${$ir['maxloan']}. Your current loan is \${$ir['loan']}.</b><br />At the end of each day, 10% of your loan amount will be taken away from your on-hand cash until you repay your loan.<br /><table width='75%' border='2'> <tr> <td width='50%'><b>Pay Back Money</b><br /><form action='loanofficer.php?action=deposit' method='post'>Amount: <input type='text' name='deposit' value='{$ir['loan']}' /><br /><input type='submit' value='Pay Back' /></form></td> <td><b>Take money</b><br /><form action='loanofficer.php?action=withdraw' method='post'>Amount: <input type='text' name='withdraw' value='$loanleft' /><br /><input type='submit' value='Take Out' /></form></td> </tr> </table>";
    }
    
    function deposit()
    {
        global $ir,$db,$userid,$h;
        $_POST['deposit']=abs((int) $_POST['deposit']);
        if($_POST['deposit'] > $ir['money'])
        {
            echo "You do not have enough money to deposit this amount.";
        }
        else
        {
            $gain=$_POST['deposit'];
            $ir['loan']-=$gain;
            mysql_query("UPDATE users SET loan=loan-$gain, money=money-{$_POST['deposit']} where userid=$userid",$db);
            echo "You hand over \${$_POST['deposit']} to be paid for your loan, <br /><b>You now have a loan of \${$ir['loan']} taken out.</b><br /><a href='loanofficer.php'>&gt; Back</a>";
        }
    }
    
    function withdraw()
    {
        global $ir,$db,$userid,$h;
        $_POST['withdraw']=abs((int) $_POST['withdraw']);
        $loanleftstill = $ir['maxloan'] - $ir['loan'];
        if($_POST['withdraw'] > $loanleftstill)
        {
            echo "You don't have enough money left in your max loan to withdraw this amount, choose a different amount or upgrade your max loan.";
        }
        else
        {
            $gain=$_POST['withdraw'];
            $ir['loan']+=$gain;
            mysql_query("UPDATE users SET loan=loan+$gain, money=money+$gain where userid=$userid",$db);
            echo "You ask for and get a loan of $gain, <br /><b>You now have a loan of \${$ir['loan']} taken out.</b><br /><a href='loanofficer.php'>&gt; Back</a>";
        }
    }
    
    
    session_start();
    require("globals.php");
    echo "<h3>Loan Officer</h3><br />Welcome to the Loan Officer!";
    if($ir['level']>=10 || $ir['user_level'] == 1)
    {
        if($ir['loan_days'] == $ir['loan_days_max'])
        {
            echo "You have had your bank account frozen. and you have lost your house.<br/>From now on until your loan balance is paid fully you will not recieve any money for your efforts.";
            $db->query("UPDATE users SET bank_frozen=1,lose_house=1 WHERE userid=$userid");
            exit;
        }
    }
    else
    {	
        switch($_GET['action'])
        {
            case "deposit": deposit(); break;
            case "withdraw": withdraw(); break;
            default: index(); 
        }
    }
    
    $h->endpage();
    ?>
    
    PHP:
    Question on the last line.... where was $h declared?

    You might also wana look into sprintf() or printf() for those long lines of text.
     
    kblessinggr, May 11, 2009 IP