duanpu8830 2018-10-31 07:21
浏览 55

在模态PHP HTML中获取值

This is my code, i was supposed to get the "$pw" outside the modal.. But it seems that i can't get the value of it and Also i can't seem to fetch the "$errMSG" value.. If it's if($pin != $pww) cant get the err MESSAGE.. Really need some help.. Thank you!

This is my "$pw" code, its on the same page as my modal..

<?php 
include('connectdb.php');
$sql = "SELECT * FROM accounts WHERE usernamee='$userid'";
$result = $conn->query($sql);
    if ($result->num_rows > 0) {
      while($data = $result->fetch_assoc()) {
        $pww = $data['passwordd'];
    }
  }
?>

This is my modal code:

<div class="container">
      <form method="post">
        <h2>Enter your Pin Number</h2>
        <!-- Trigger the modal with a button -->
        <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
        <!-- Modal -->
        <div class="modal fade" id="myModal" role="dialog">
          <div class="modal-dialog">
            <!-- Modal content-->
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Enter your Pin Number</h4>
              </div>
              <div class="modal-body text-center">
                <input type="password" id="first-name" required="required" class="form-control" name="pin">

                <?php
                  if(isset($errMSG)){
                   ?>
                        <div class="alert alert-danger">
                            <span class="glyphicon glyphicon-infos-sign"></span> <strong><?php echo $errMSG; ?></strong>
                        </div>
                  <?php
                  }
                  else if(isset($successMSG)){
                  ?>
                        <div class="alert alert-success">
                              <strong><span class="glyphicon glyphicon-info-sign"></span> <?php echo $successMSG; ?></strong>
                        </div>
                  <?php
                  }
                  ?>

              </div>
              <div class="modal-footer">
                <button type="submit" name="submit3" class="btn btn-default"><i class="fa fa-key"></i> Confirm Pin</button>
              </div>
            </div>             
          </div>
        </div>
        <!-- START OF PHP -->
          <?php include ('connectdb.php');
          if(isset($_POST['submit3']))
          {    
             $pin = $_POST["pin"];
             if ($pin != $pww) {
               $errMSG= "WRONG PIN.. TRY AGAIN..";
             }
             else{
                header('Location: myorders.php');
             }
          } // SUBMIT 
          ?>
        </form>
      </div>
  • 写回答

1条回答 默认 最新

  • dongming0505 2018-10-31 07:47
    关注
    include('connectdb.php');
    $pww = '';
    $sql = "SELECT * FROM accounts WHERE usernamee='$userid'";
    $result = $conn->query($sql);
        if ($result->num_rows > 0) {
          while($data = $result->fetch_assoc()) {
            $pww = $data['passwordd'];
          }
        }
    

    Try this code, You should declare pww before your if or while brackets, to get acces to this variable.

    评论

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂