通过POST PHP发送更多价值

时间:2020-02-18 21:03:46

标签: php html

这是我的第一篇帖子,非常欢迎!

我在项目中遇到一个难题。如您在我的屏幕截图中所见,我有几个名称是从数据库中获取的,并显示在主菜单中。单击“模态”按钮后,引导程序的模态以php形式显示。用户可以输入4位数的密码,下一步是将该密码与数据库记录匹配。但是2个用户可以具有相同的pin,所以我不仅需要比较与数据库的pin,还需要比较名称。我不知道如何用邮寄发送“名称”值。这是我的代码和屏幕截图:

index.php:

  <?php 
 $data = $worker->select_workers();
$worker->show_workers($data);
$worker->show_modal();

worker.php:

<?php 
require_once('db.php');
class Worker extends db {

protected $select_workers;
    public function select_workers(){

                return $this->select_workers = $this->query('SELECT * FROM worker')->fetchAll();
    }

    public function show_workers($data){
        foreach ($data as $users) {
    echo '<p id="p_name">'.$users['name'].'</p><a id="button_modal" href="/?name='.$users['name'].'" type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
  Modal
</a><br>';

}
}
    public function show_modal(){
echo '<!-- Button trigger modal -->


<!-- Modal -->
<form action="test.php" id="submit_ajax" method="post">
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modal_title" name="name"></h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <input id="hidden_name" type="text" value="" name="name" />
Hasło:<input type="text" name="password"><br>



      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button  type="submit" class="btn btn-primary">Przerwa/powrót</button>
        </form>
      </div>
    </div>
  </div>
</div>';
    }

Main menu of my application

我相信该解决方案确实很简单,但是像往常一样-我浪费太多时间处理无法正常工作的复杂事情。对不起,我的英语不是我的母语:) 谢谢

2 个答案:

答案 0 :(得分:0)

<input id="hidden_name" type="text" value="<?= $name ?>" name="name" />处输入值,但是如果您从db中获取数据,使用id代替名称不是更好吗?

答案 1 :(得分:0)

不干净的溶液。为每个工人树立模范。

<?php 
require_once('db.php');
class Worker extends db {

protected $select_workers;
    public function select_workers(){

                return $this->select_workers = $this->query('SELECT * FROM worker')->fetchAll();
    }

    public function show_workers($data){
        $i=0;
        foreach ($data as $users) {
        $i++;
    echo '<p id="p_name">'.$users['name'].'</p><a id="button_modal" href="/?name='.$users['name'].'" type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal'.$i.'">
  Modal
</a><br>
<!-- Button trigger modal -->


<!-- Modal -->
<form action="test.php" id="submit_ajax" method="post">
<div class="modal fade" id="exampleModal'.$i.'" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modal_title" name="name"></h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <input id="hidden_name" type="text" value="'.$users['name'].'" name="name" />
Hasło:<input type="text" name="password"><br>



      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button  type="submit" class="btn btn-primary">Przerwa/powrót</button>
        </form>
      </div>
    </div>
  </div>
</div>';
    }