如何使用if语句检查用户帐户中的值

时间:2013-04-17 11:31:09

标签: php function if-statement

我有以下功能,简单地说,它允许从一个用户帐户获取一个值并放入另一个用户帐户。现在我需要做的是检查该成员是否有足够的硬币可用于与另一个用户交换内容。如果该成员没有足够的可用硬币,则需要显示一条消息。

到目前为止,即使我知道该成员有足够的硬币,该消息也不会显示任何内容。我做错了什么?谢谢。

function Exchange()
{
    // Extract transaction details from POST.
    $Transaction['OddJobID']=$_POST['OddJobID'];
    $Transaction['MemberID']=$_SESSION['MemberID'];

    // Get the odd job details and current users details.
    $valueResult = mysql_fetch_assoc(mysql_query("SELECT * FROM `Oddjob` WHERE `OddJobID` = '{$Transaction['OddJobID']}'"));
    $coinsAvail = mysql_fetch_assoc(mysql_query("SELECT * FROM `member` WHERE `MemberID` = '{$Transaction['MemberID']}'"));

    if ($coinsAvail['CoinsAvailable'] > $valueResult['CoinValue']){
        // Calculate new balance when current users available
        // balance is debited by the value of the odd job.
        $newBalance = $coinsAvail['CoinsAvailable'] - $valueResult['CoinValue'];


        // Create new transaction for odd job and
        // get the user id from the username.
        $success = TransactionTbl ($Transaction);
        $Transaction['MemberID'] = user_id_from_username ($Transaction['MemberID']);

        mysql_query("UPDATE `member` SET `CoinsAvailable` = '$newBalance' WHERE `MemberID` = '{$Transaction['MemberID']}'");

        // Get ID from odd job row and calculate the new balance
        // of the person providing the odd job when the recieve
        // payment.
        $valueResultAdd = mysql_fetch_assoc(mysql_query("SELECT * FROM `Member` WHERE `MemberID` = '{$valueResult['MemberID']}'"));
        $newBalance8 = $valueResultAdd['CoinsAvailable'] + $valueResult['CoinValue'];

        // Update the odd job provider with their new calculated balance.
        mysql_query("UPDATE `member` SET `CoinsAvailable` = '$newBalance8' WHERE `MemberID` = '{$valueResultAdd['MemberID']}'");

        // Redirect to index page.
        header('location: index.php');
    }
    else{
        echo"<script type=\"text/javascript\">".
            "alert('Sorry you do not have enough coins to exchange this service.');".
            "</script>";
    }
    exit();
}

0 个答案:

没有答案