Problem in Code?

Discussion in 'PHP' started by mokimofiki, Sep 23, 2008.

  1. #1
    I can't seem to figure out where I am going wrong .... it could be everywhere although any help would be great thank you in advance.

    $statsmain = mysql_query("SELECT * FROM statsmain WHERE statsuid='$uid'");
    while($row = mysql_fetch_array($statsmain))
    
    $cash = $row['cash'];
    $depositamt = $_POST["depositamt"];
    $bank = $row['bank'];
    
    if("$depositamt" <= "$cash")
    {
    $cashremaining = "$cash" - "$depositamt";
    
    $depminus10p = "$depositamt" *.9;
    $banknewamt = "$depminus10p" + "$bank";
    
    mysql_query("UPDATE statsmain SET cash = $cashremaining WHERE statsuid = $uid");
    
    mysql_query("UPDATE statsmain SET bank = $banknewamt WHERE statsuid = $uid");
    Code (markup):
     
    mokimofiki, Sep 23, 2008 IP
  2. chmdznr

    chmdznr Active Member

    Messages:
    417
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #2
    
    $statsmain = mysql_query("SELECT * FROM statsmain WHERE statsuid='$uid'");
    while($row = mysql_fetch_array($statsmain)) {
    $cash = $row['cash'];
    $depositamt = $_POST["depositamt"];
    $bank = $row['bank'];
    
    if($depositamt <= $cash) {
    $cashremaining = $cash - $depositamt;
    
    $depminus10p = $depositamt*.9;
    $banknewamt = $depminus10p + $bank;
    
    mysql_query("UPDATE statsmain SET cash = $cashremaining WHERE statsuid = $uid");
    
    mysql_query("UPDATE statsmain SET bank = $banknewamt WHERE statsuid = $uid");
    } //end if
    } //end while
    
    Code (markup):
    That could the code you want. You should post more detailed algorithm of your program!
     
    chmdznr, Sep 23, 2008 IP
  3. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #3
    the while(), you did not put a curly bracket after it. { }
     
    ads2help, Sep 24, 2008 IP
  4. h0ly lag

    h0ly lag Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This should work. Like ads2help said, you forgot the curly brackets for your while statement. You also put a beginning bracket for your if statement, but no closing one. :)

    <?php
    $statsmain = mysql_query("SELECT * FROM statsmain WHERE statsuid='$uid'");
    
    while($row = mysql_fetch_array($statsmain))
    	{
    $cash = $row['cash'];
    $depositamt = $_POST["depositamt"];
    $bank = $row['bank'];
    
    	if("$depositamt" <= "$cash")
    		{
    		$cashremaining = "$cash" - "$depositamt";
    		$depminus10p = "$depositamt" *.9;
    		$banknewamt = "$depminus10p" + "$bank";
    
    		mysql_query("UPDATE statsmain SET cash = $cashremaining WHERE statsuid = $uid");
    		mysql_query("UPDATE statsmain SET bank = $banknewamt WHERE statsuid = $uid");
    		}
    	}
    ?>
    PHP:
     
    h0ly lag, Sep 24, 2008 IP
  5. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #5
    and all these were wrong
            $cashremaining = "$cash" - "$depositamt";
            $depminus10p = "$depositamt" *.9;
            $banknewamt = "$depminus10p" + "$bank";
    PHP:
    just follow the chmdznr's
     
    ads2help, Sep 25, 2008 IP