选择选项中的多个值会在比较爆炸值时返回不正确的条件

时间:2017-10-13 11:21:38

标签: php html mysqli

我有两个选择框,每个选项中包含多个值,用于保存用户的名称和包裹数量。在他们能够合并用户付款之前我需要确保他们合并用户具有相同的包金额。但是当我爆炸每个选项中的值并比较包装数量时,即使包装数量相同,它仍然会给我错误。

为了使我的解释清楚,这是截图和源代码:

enter image description here

html源代码:

<div class="row"> 
         <!-- BEGIN ALERT - REVENUE -->
         <form method="post" action="">
        <div class="col-lg-5 col-md-5 col-sm-5" style="margin-bottom:15px;">
          <p style="font-weight:bolder; font-size:16px;">New Members</p>

          <p>
          <select name="new_user" class="form-control">
           <option value="">New Members</option>
          <?php 
         $new = mysqli_query($mysqli, "SELECT * FROM package");
         while($n = mysqli_fetch_array($new)){
          ?>
         <option value="<?php echo $n['username'] . "-" . $n['package_amount'];?>"><?php echo $n['username'];?> - <?php echo $n['package_amount'];?></option>

         <?php
         }
         ?>
          </select>
          </p>

        </div>
        <!--end .col --> 
        <!-- END ALERT - REVENUE --> 

        <!-- BEGIN ALERT - VISITS -->
        <div class="col-lg-5 col-md-5 col-sm-5" style="margin-bottom:15px;">
           <p class="user-header" style="font-weight:bolder; font-size:16px;">Members Awaiting Payment</p>

          <p>
          <select name="awaiting_payment" class="form-control">
          <option value="">Awaiting Payment</option>
          <?php 
         $news = mysqli_query($mysqli, "SELECT * FROM payment_queue");

         if(mysqli_num_rows($news) < 1){
            echo '<option value="">No Users Awaiting Payment at the Moment</option>'; 
         }else{
         while($n2 = mysqli_fetch_array($news)){
          ?>
         <option value="<?php echo $n2['username'] . "-" . $n2['package_amount'];?>"><?php echo $n2['username'];?> - <?php echo $n2['package_amount'];?></option>

         <?php
         }
         }
         ?>
          </select>
          </p>

      </div>
      <!-- /.row -->
      <div class="col-lg-10">
      <div align="center"><button type="submit" name="submit" value="merge" class="btn btn-info btn-sm"><span class="fa fa-flag"></span> Merge</button></div>
      </div>
      </form>

</div>

这是处理源代码:

// Manual Merging
    if (isset($_POST['submit']) && $_POST['submit'] == 'merge') {
        //payee
        $value = $_POST['new_user'];    
        $payees = explode('-',$value);
        $name = $payees[0];
        $package = $payees[1];

        //collector
        $col = $_POST['awaiting_payment'];  
        $ap = explode('-',$col);
        $aname = $ap[0];
        $apn = $ap[1];

        if($_POST['new_user'] == "") {
            $newErr = "Select from new users a sponsor";
            $msgBox = alertBox($newErr, "<i class='fa fa-times-circle'></i>", "danger");
        } else if($_POST['awaiting_payment'] == "") {
            $await = "Select member to be sponsor from awaiting payment list"; 
            $msgBox = alertBox($await, "<i class='fa fa-times-circle'></i>", "danger");
        }//else if(!empty($_POST['new_user']) && !empty($_POST['awaiting_payment'])){
        else if(mysqli_num_rows(mysqli_query($mysqli, "SELECT * FROM to_be_paid WHERE username='".$_POST['awaiting_payment']."'"))>0){
        $user_error= $_POST['awaiting_payment']. " has already been assigned a member for payment";
        $msgBox = alertBox($user_error, "<i class='fa fa-times-circle'></i>", "danger");
        }
        else if(mysqli_num_rows(mysqli_query($mysqli, "SELECT * FROM to_be_paid WHERE payee_username='".$_POST['new_user']."'"))>0){
        $user_e= $_POST['new_user']. " has already been assigned to pay.";
        $msgBox = alertBox($user_e, "<i class='fa fa-times-circle'></i>", "danger");
        }       

        else if($package_name != $apn){
        $p_error= " The package of ". $package ." you are merging with " . $apn . " are not the same package. You need to merge package of the same denomination.";
        $msgBox = alertBox($p_error, "<i class='fa fa-times-circle'></i>", "danger");   
        }



        //}
        else {
                //payee
                $value = $_POST['new_user'];    
                $payees = explode('-',$value);
                $name = $payees[0];
                $package = $payees[1];

                //collector
                $col = $_POST['awaiting_payment'];  
                $ap = explode('-',$col);
                $aname = $ap[0];
                $apn = $ap[1];
                //select from package table
                //This is the payee
                $paye =  mysqli_query($mysqli, "SELECT * FROM package WHERE username='$name' and package_amount= '$package'");
                $payee = mysqli_fetch_array($paye);

                //select from payment_queue table. This are people awaiting payment.

                $awaiting =  mysqli_query($mysqli, "SELECT * FROM payment_queue WHERE username='$aname' and package_amount='apn'");
                $await = mysqli_fetch_array($awaiting);

                //variable
                                $unames = $await['username'];
                                $ban = $await['bank_account_number'];
                                $pa = $await['package_amount'];
                                $puname = $payee['username'];
                                $ppn = $payee['phone_number'];
                                $pban = $payee['bank_account_name'];
                                $pbano = $payee['bank_account_number'];
                                $pbn = $payee['bank_name'];
                                $ppa = $payee['package_amount'];
                                //$date = date('Y-m-d H:i:s');
                                $now = date("Y-m-d H:i:s");
                                $tim = '+'.$set['donation_time'];
                                $date = date("Y-m-d H:i:s", strtotime($tim.' hours', strtotime($now))); 

            //insert details into to_be_paid table

            $stmts = mysqli_query($mysqli, "
                                INSERT INTO
                                    to_be_paid( 
                                        username,
                                        bank_account_number,
                                        package_amount,
                                        payee_username,
                                        payee_number,
                                        payee_bank_account_name,
                                        payee_bank_account_number,
                                        payee_bank_name,
                                        payee_package_number,
                                        datetime
                                        ) VALUES (
                                        '$unames',
                                        '$ban',
                                        '$pa',
                                        '$puname',
                                        '$ppn',
                                        '$pban',
                                        '$pbano',
                                        '$pbn',
                                        '$ppa',
                                        '$date'

                                    )
            ");

                if($stmts){     
            //mysqli_query($mysqli, "DELETE FROM package WHERE username='".$_POST['new_user']."'");

            $mergeOk = "Successfully Assigned " . $puname ." to ". $unames . " for Payment";
            $msgBox = alertBox($mergeOk, "<i class='fa fa-check-square'></i>", "success");
            //add to assign table
    mysqli_query($mysqli,
    "INSERT INTO 
    assign(
    username,
    bank_account_number,
    package_amount,
    payee_username,
    payee_bank_account_number

    ) 
    VALUES(
    '$unames',
    '$ban',
    '$pa',  
    '$puname', 
    '$pbano'
    )");

                    //delete person to be paid from payment_queue table
                    mysqli_query($mysqli,"DELETE FROM payment_queue WHERE username='$aname' AND package_amount='$apn'");
                    //delete person to be paid from assign table
                    mysqli_query($mysqli,"DELETE FROM assign WHERE username='$aname' AND package_amount='$apn'");

                }else{
                    $mergeErr = "There was an error assigning " . $puname ." to ". $unames . " for Payment. Please try again later.";
            $msgBox = alertBox($mergeErr, "<i class='fa fa-check-square'></i>", "danger");
                }

        }
    }

我搜索过堆栈流和我可以找到的在线资源,但非能够指出我正确的道路。

1 个答案:

答案 0 :(得分:0)

从你的代码:

else if($package_name != $apn){
    $p_error= " The package of ". $package ." you are merging with " . $apn . " are not the same package. You need to merge package of the same denomination.";
    $msgBox = alertBox($p_error, "<i class='fa fa-times-circle'></i>", "danger");   
    }

$ package_name未在代码中的任何位置定义。可能是$ package而已?