[英]Select * from table where colum = username not working
我正在嘗試在支付網關為 stipe 的網站上實施折扣代碼,一切正常,但是當我嘗試根據促銷代碼獲取折扣百分比時,用戶從數據庫輸入的數據不起作用,而不是收取折扣價,它收取全價,完全忽略折扣
這里的代碼
$getcode = $getcode[1];
$user = $_SESSION['username'];
$total = $_SESSION['totprice'];
$sql6 = 'SELECT * from promocode where username="'.$user.'" and promo_code="'.$getcode.'" ';
$result6 = mysqli_query($con, $sql6);
while($row6 = mysqli_fetch_assoc($result6)) {
echo "Discount: " . $row6["discount"]. "<br>";
$discount =$row6["discount"];
$grandtotal= $total - (($discount * $total) / 100);
$publishable_key = "*******************";
$secret_key = "********************";
if(isset($_POST['stripeToken'])){
Stripe::setApiKey($secret_key);
$description = "Invoice #".rand(99999,999999999) ;
$amount = $grandtotal;
$user = $_SESSION['username'];
所以而不是
$amount = $total - (($discount * $total) / 100);
它給了我
$amount = $total;
因為某些原因
你沒有累積所有的折扣。 每次循環時,您只需將當前行的折扣應用於總數,覆蓋您從前幾行計算的內容。
將$grandtotal
初始化$grandtotal
總數,然后每次從中減去。
此外,您不應該允許大量折扣讓總計低於 0。我在最后檢查了這一點。
$grandtotal = $total;
while ($row6 = mysqli_fetch_assoc($result6)) {
echo "Discount: " . $row6["discount"]. "<br>";
$discount = $row6["discount"];
$grandtotal -= $total - (($discount * $total) / 100);
}
if ($grandtotal < 0) {
$grandtotal = 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.