dqq48152418 2017-11-24 20:08
浏览 10

你如何只在按下按钮运行PHP帖子

Whenever I refresh the page the modal automatically opens even though I don't press the button. Is there a way in my if statement to make it only open when the button is pressed? Thanks!

I am very new to PHP so my code may not be efficient.

<?php
                            include_once 'includes/database.php';
                            if ($_SESSION['renterID'] == 0){
                              $sql = "SELECT firstName, lastName, paymentID, paymentAmount, paymentDate, paymentPaid FROM renter, payment WHERE renter.renterID = payment.renterID ORDER BY paymentDate ASC";

                            } else {
                              $sql = "SELECT firstName, lastName, paymentID, paymentAmount, paymentDate, paymentPaid FROM renter, payment WHERE renter.renterID = payment.renterID AND $_SESSION[renterID] = renter.renterID";
                            }
                            $result = mysqli_query($conn, $sql);
                            $resultCheck = mysqli_num_rows($result);
                            if ($resultCheck > 0) {
                              while($row = $result->fetch_assoc()) {
                                echo
                                "<tr>
                                    <td>$row[paymentID]</td>
                                    <td>$row[firstName] $row[lastName]</td>
                                    <td>$row[paymentAmount]</td>
                                    <td>";echo date ('F d, Y', strtotime($row['paymentDate'])); echo "</td>";
                                    if ($_SESSION['renterID'] == 0) {
                                      if ($row['paymentPaid'] == '0') {
                                        echo "<td class='text-center'><a class='btn btn-danger btn-sm'><i class='fa fa-times' aria-hidden='true'>Paid</i></a></td>";
                                      } else {
                                        echo "<td class='text-center'><a class='btn btn-success btn-sm'><i class='fa fa-check' aria-hidden='true'>Paid</i></a></td>";
                                      }
                                    } else {
                                    if ($row['paymentPaid'] == '0'){
                                      echo "

                                          <td class='text-center'><button href='#' class='btn btn-success btn-sm' id='payNowButton' name='payNowID' value='$row[paymentAmount]'><i class='fa fa-usd' aria-hidden='true'>Pay Now</i></button></td>

                                      ";
                                    } else {
                                      echo "<td class='text-center'><a class='btn btn-sm'><i class='fa fa-check' aria-hidden='true'>Paid</i></a></td>";
                                    }
                                  }
                                echo "</tr>";
                              }
                            } else {
                              echo "<tr><td colspan='5'>No payments at this time</td></tr>";
                            }


    <?php
  if(isset($_POST['payNowID'])){
    $totalAmount = $_POST['payNowID'];

    echo "<script>
    $(document).ready(function() {
      $('#payNowButton').click(function() {
        $('#pay_now').modal('show');
      });
    });
    </script>";
  }
?>
  • 写回答

1条回答 默认 最新

  • doudou0111 2017-11-24 20:16
    关注

    This isn't a php problem, rather this is a jQuery problem. You are setting in jQuery that it must show the modal on document ready. That is because it shows up. Replace your jQuery method with:

    $(document).ready(function() {
     $('.btn').click(function() {
       $('#pay_now').modal('show');
      });
    });
    

    This way the modal will be shown only if you click the button.

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)