about if else statements

Discussion in 'PHP' started by novanakal, Jan 2, 2014.

  1. #1
    hiii, im new here.
    and php isnt my main working, just want to learn something bout this.

    i got an error when iam using this code..

    can you all correct my php..

    thx before


    <?php
    include 'connect.php';
    $sql    =    mssql_query(" SELECT Account, AccountSerial FROM $rfworld.dbo.tbl_base WHERE Account = '".$_POST['accountname']."' ");
    $sql2    =    mssql_query(" SELECT SerialAccount FROM $billing.dbo.tbl_usercash ");
    $result    =    mssql_fetch_assoc( $sql);
    $result2    =    mssql_fetch_assoc( $sql2);
    $baseaccount= $result['Account'];
    $baseserial = $result['AccountSerial'];
    $billingserial = $result2['SerialAccount'];
    $serialid = ($result['AccountSerial'] = $result2['SerialAccount'] );
    
    if ( $baseaccount == NULL )
    {
        $serialresult    =    ' <p>Account not find</p> ' ;
    
    }
    if ( $baseaccount = $baseserial && $billingserial == NULL )
    {
        $serialresult = '<p> Cash Coin not Aktif </p>';
        include    'insert.php';
    }
      
    if ( $baseaccount = $baseserial  && $billingserial = $baseaccount)
    {
        $serialresult = '<p> Cash Coin Aktif </p>';
    }
    
    
    
    
    mssql_close($sql);
    mssql_close($sql2);
    ?>
    <?php
    echo ' '.$serialresult.' ';
    ?>
    
    
    
    PHP:

    ill explain bout my problem..

    ive 2 DB,....
    worlddb and billingdb.

    worlddb have a AccountSerial from tbl_base, and billingdb have SerialAccount from tbl_usercash.

    i want to all user have an activation from website, in case..
    AccountSerial from tbl_base inserting into SerialAccount tbl_usercash.

    when they search in website with AccountName, it will print AccountSerial..
    Coz AccountName and AccountSerial have a one table.

    after Print AccountName, should we got the AccountSerial,.. and Than Update with insert to billingdb tbl_usercash.

    iam so confuse bout it, have 5 hour for solving.. but nothing :(

    ill really appriciate if you all can help me with some logic or clue..

    thx before
     
    Last edited: Jan 2, 2014
    novanakal, Jan 2, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    You need to learn the difference between '=' (assign) and '==' (compare) - you want to compare in the if-statements...
     
    PoPSiCLe, Jan 2, 2014 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    Pretty much that's the root of the problem -- single equals is assignment, double equals is compare. BIG difference.

    That and the code really is gibberish, and ignores one of the prime rules of using IF, avoid checking the same value more than once... mssql_close is done on the connection, NOT the queries... and this is 2014 not 2007, so much like mysql_ functions you shouldn't be using mssql_ functions, you should be using PDO. Usually one also does NOT go "== NULL" in PHP, you check for "isset"

    The if statements I'd probably nest like this -- doing so exposes that you have an unhandled state too.

    if (isset($baseAccount)) {
    	if ($baseAccount == $baseSerial) {
    		if (isset($billingSerial)) {
    			$serialResult = '<p>Cash Coin Not Aktif</p>'; // WTF is Aktif?!?
    			include('insert.php');
    		} else {
    			$serialResult = '<p>Cash Coin Aktif</p>';
    		}
    	} else {
    		/* unhandled result, you should do something here! */
    	}
    } else $serialResult = '<p>Account Not Found</p>';
    Code (markup):
    As to the rest of that, your queries are gibberish, I'm not even certain they'd only return one rowset, particularly that latter one. Just what is it you are even trying to do?!?
     
    deathshadow, Jan 3, 2014 IP