添加内部循环引导程序模式会使数据库重复输入

时间:2018-09-20 09:01:21

标签: php

<div class="widget-content">
          <br>          
          <?php
            $query="select * from tbl_voter where voter_status='Active' && voter_college='".$_GET['cname']."'";
            $res=mysql_query($query);
            while ($row=mysql_fetch_array($res)) {
          ?> 
          <div style="margin-left: 40px;" class="floating-box">  
          <table class="table table-striped table-bordered" style="width: 300px; height: 300px;">
            <thead>
              <tr>
                <th>Voter Details</th>
              </tr>
            </thead>
            <tbody>
              <tr>
              <td><center><img width="150" height="100"  src="<?php echo $row['file_location'].$row['voter_pic'];?>">
                <br>
                <?php echo $row['voter_firstName']." ". $row['voter_lastName'];?><br>
                  <?php echo $row['voter_college']?><br>
                  <?php echo $row['voter_course']?><br>
                  <a href="" data-toggle="modal" data-target="#myModal<?php echo $row['voter_id'];?>" class="btn btn-small" data-toggle="tooltip" title="Update Profile">
                    <button class="btn btn-primary">Update</button>                 
                  </a>
                  <a href="" data-toggle="modal" data-target="#delModal<?php echo $row['voter_id'];?>" class="btn btn-small" data-toggle="tooltip" title="Delete Profile">
                    <button class="btn btn-danger">Delete</button>                   
                  </a>
                  </center>

this is the modal for update
  <div id="myModal<?php echo $row['voter_id'];?>" class="modal fade" 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>
      </div>
      <div class="modal-body">
        <form method="POST" action="" enctype="multipart/form-data">
          <input type="hidden" name="id" value="<?php echo $row['voter_id'];?>">
          <center> <img src="<?php echo $row['file_location'].$row['voter_pic'];?>" height="200" width="200"><input type="file" name="voter_pic"></center><br>
          <b>Student ID</b>
          <input type="text" name="studentID" value="<?php echo $row['studentID'];?>" class="form-control input-sm">
        <b>First Name</b>
        <input type="text" name="fname" value="<?php echo $row['voter_firstName'];?>" class="form-control input-sm"><br>
        <b>Middle Name</b>
        <input type="text" name="mname" value="<?php echo $row['voter_middleName'];?>" class="form-control input-sm"><br>
        <b>Last Name</b>
        <input type="text" name="lname" value="<?php echo $row['voter_lastName'];?>" class="form-control input-sm"><br>
        <b>Gender</b>
        <select name="gender" class="form-control input-sm">
          <option><?php echo $row['voter_gender'];?></option>
          <option>Male</option>
          <option>Female</option>
        </select>
        <b>College</b>
        <select id="collegename" name="college" class="form-control input-sm">
          <option><?php echo $row['voter_college'];?></option>
          <option>------------</option>
          <?php
            $query2="select * from tbl_college where college_status='Active'";
            $res2=mysql_query($query2);
            while ($row2=mysql_fetch_array($res2)) {
          ?>
            <option><?php echo $row2['college_name'];?></option>
          <?php
            }
          ?>
        </select>
        <b>Course</b>
        <select   name="course" class="form-control input-sm">
        <?php
        $query3="select * from tbl_course where course_status='Active'";
        $res3=mysql_query($query3);
        while ($row3=mysql_fetch_array($res3)) {
        ?>
        <option><?php echo $row3['course_name'];?></option>
        <?php
        }
        ?>
        </select>
      </div>
      <div class="modal-footer">
        <input type="submit" name="update" value="Update" class="btn btn-primary">
        <?php
          updateVoter();
        ?>
        </form>
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>
<!-- Modal -->
<div id="delModal<?php echo $row['voter_id'];?>" class="modal fade" 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>
      </div>
      <div class="modal-body">
        <b>Are You sure you want to delete this voter <?php echo $row['voter_firstName']." ".$row['voter_lastName'];?></b>
      </div>
      <div class="modal-footer">
        <form method="POST" action="">
        <input type="hidden" name="id" value="<?php echo $row['voter_id'];?>">
        <input type="hidden" name="stid" value="<?php echo $row['studentID'];?>">
        <input type="hidden" name="name" value="<?php echo $row['voter_firstName']." ".$row['voter_lastName'];?>">
        <input type="submit" name="delete" class="btn btn-danger" value="Delete">
        <?php
          deleteVoter();
        ?>
        </form>
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
              </td>   
              </tbody>
            </table>
            </div>
          <?php

            }
          ?>

        </div> <!-- /widget-content -->
      </div> <!-- /widget -->
            </div>
    </div>

解决我的问题的方法是什么,它继续根据我在添加到数据库中时查询获得的行数进行重复输入。模态有其自己的唯一ID,可从一行中访问不同的数据,但是每当我单击时更新按钮,它根据查询获得的行数进行更新。我正在添加用户日志,这就是为什么我知道它自我更新了多少次

0 个答案:

没有答案