doukeng1922
doukeng1922
2015-01-16 14:59

单个提交按钮上有两个_POST

已采纳

i have the code of my POST action , but is very long , with two different actions , if the user has the card to buy with money from the vault , and if the user has not the card upgrade the code is something like this :

if (isset($_POST['shop'])) {
if (security($_POST['ccard']) == 1) {
$umoney = $urow['bank'] + $urow['money'];
    } else {
$umoney = $urow['money'];
}
mysql_query(set the total upgrade values in another table)
mysql_query(give the user upgrade values in another table)
}
    if (security($_POST['ccard']) == 1) {
    $upuser = mysql_query("UPDATE `users` SET bank=bank-'$sumtotc' WHERE id='$urow[id]'");
    } else {
$upat2 = mysql_query("UPDATE `users` SET money=money-'$sumtotc' WHERE id='$urow[id]'");
}

but if i do so , if the user buy something that the value is more than bank , it will be with minus value in bank , i tried with this :

if ($urow['bank'] < 0) {
$upmon = mysql_query("UPDATE `users` SET money=money-'$urow[bank]' WHERE id='$urow[id]'");
$upban = mysql_query("UPDATE `users` SET bank=0 WHERE id='$urow[id]'");
}

Is there another way to make the ccard funtion better? and the value of the bank not to be negative ?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douzheng5717 douzheng5717 6年前

    You can Use IF statement like :

    $upuser = mysql_query("UPDATE `users` 
    SET bank = 
        CASE 
            WHEN bank-'$sumtotc' <= 0  
                THEN 0 
            WHEN bank-'$sumtotc' >= 1 
                THEN bank-'$sumtotc' 
        END 
    money = 
        CASE 
            WHEN bank-'$sumtotc' <= 0  
                THEN money-'$urow[bank]'
            WHEN bank-'$sumtotc' >= 1 
                THEN money-'$sumtotc'
        END 
    
    WHERE id='$urow[id]'");
    

    http://dev.mysql.com/doc/refman/5.0/en/if.html

    点赞 评论 复制链接分享