无法将Mysql表中的所有检索数据存储到我的新html表单中


unable to store my all retrieve the data from the Mysql table to my new html form.

这里我遇到了while循环的问题。。(我想)无法将我的所有数据从Mysql表检索到我的html表单。

由于while循环中的相同名称元素被重复,中的第一行只被发布,其余行没有发布

此处为$_POST['mechanic_name'];有一次我在用。。这个有问题吗。。因为这不是一个循环,或者如果你认为下面的代码有任何其他问题,请建议

<?php
                  include("db_conection.php");
                  $view_users_query="select * from mechanic";//select query for viewing users.
                  $run=mysqli_query($dbcon,$view_users_query);//here run the sql query.
                  while($row=mysqli_fetch_array($run))//while look to fetch the result and store in a array $row.
                  {
                      $mechanic_ID=$row[0];
                      $mechanic_name=$row[1];
                       
                  ?>
             
                  <tr>                       
                      <td>
                         <input name="mechanic_ID" type="text" value="<?php echo $mechanic_ID;  ?>">    
                      </td>
                      <td>
                      <input name="mechanic_name" type="text" value="<?php echo $mechanic_name;  ?>">  
                      </td>
</tr>
<!--* For save php script*-->
<?php
include("db_conection.php");//make connection here
if(isset($_POST['register']))
{
    $mechanic_ID=$_POST['mechanic_ID'];//here getting result from the post array after submitting the form.
          $mechanic_name=$_POST['mechanic_name'];//same
          $month=$_POST['month'];//same
                   
    
    if($mechanic_name=='')
    {
        //javascript use for input checking
        echo"<script>alert('Please enter the name')</script>";
    exit();//this use if first is not work then other will not show
    }
//insert the user into the database.
$insert_schedule="insert into schedule (mechanic_ID,mechanic_Name,) VALUE ('$mechanic_ID','$mechanic_name'[enter image description here][1])";
  if(mysqli_query($dbcon,$insert_schedule))
    {
        echo"<script>window.open('index.html','_self')</script>";
    }
}

请帮帮我

<div>
      <form role="form" method="post" action="schedule.php">
         <table class="table table table-inverse table-hover">
          <fieldset>
              <div>
                <input class="form-control" placeholder="Username" name="month" type="Month" value="January">
              </div>
            <thead class="thead-inverse">
               <tr>
                <th>Mechanic Id</th>
                <th>Mechanic Name</th>
                <th>Woking Day Selection</th>
                <th>Delete User</th>
              </tr>
            </thead>

                  <?php
                  include("db_conection.php");
                  $view_users_query="select * from mechanic";//select query for viewing users.
                  $run=mysqli_query($dbcon,$view_users_query);//here run the sql query.
                  while($row=mysqli_fetch_array($run))//while look to fetch the result and store in a array $row.
                  {
                      $mechanic_ID=$row[0];
                      $mechanic_name=$row[1];      
                  ?>
                  <tr>                    
                      <td>
                         <input name="mechanic_ID" type="text" value="<?php echo $mechanic_ID;  ?>">    
                      </td>
                      <td>
                      <input name="mechanic_name" type="text" value="<?php echo $mechanic_name;  ?>">  
                      </td>   
                      <td>
                        <div class="weekDays-selector">
                          <input type="checkbox" name="Sun" id="weekday-sun" class="weekday" />
                            <label for="weekday-sun">S</label>
                          <input type="checkbox" name="Mon" id="weekday-mon" class="weekday" />
                            <label for="weekday-mon">M</label>
                          <input type="checkbox"  name="Tue" id="weekday-tue" class="weekday" />
                            <label for="weekday-tue">T</label>
                          <input type="checkbox"  name="Wed" id="weekday-wed" class="weekday" />
                            <label for="weekday-wed">W</label>
                          <input type="checkbox"  name="Thu" id="weekday-thu" class="weekday" />
                            <label for="weekday-thu">T</label>
                          <input type="checkbox"  name="Fri" id="weekday-fri" class="weekday" />
                            <label for="weekday-fri">F</label>
                          <input type="checkbox"  name="Sat" id="weekday-sat" class="weekday" />
                            <label for="weekday-sat">S</label>
                          </div>
                      </td>
                        <td>
                            <!--button-->
                            <input class="btn btn-lg btn-success btn-block" type="submit" value="register" name="register" >
                        </td>
                  </tr>
            </fieldset> 
                  <?php } ?>
                  </table>
          </form>
        </div>

              <?php
include("db_conection.php");//make connection here
if(isset($_POST['register']))
{
    $mechanic_ID=$_POST['mechanic_ID'];//here getting result from the post array after submitting the form.
          $mechanic_name=$_POST['mechanic_name'];//same
          $month=$_POST['month'];//same
          $Sun=$_POST['Sun'];//same
          $Mon=$_POST['Mon'];//same
          $Tue=$_POST['Tue'];//same
          $Wed=$_POST['Wed'];//same
          $Thu=$_POST['Thu'];//same
          $Fri=$_POST['Fri'];//same
          $Sat=$_POST['Sat'];//same
    if($mechanic_name=='')
    {
        //javascript use for input checking
        echo"<script>alert('Please enter the name')</script>";
    exit();//this use if first is not work then other will not show
    }
//insert the user into the database.
$insert_schedule="insert into schedule (mechanic_ID,mechanic_Name,month,Sun,Mon,Tue,Wed,Thu,Fri,Sat) VALUE ('$mechanic_ID','$mechanic_name','$month','$Sun','$Mon','$Tue','$Wed','$Thu','$Fri','$Sat')";
  if(mysqli_query($dbcon,$insert_schedule))
    {
        echo"<script>window.open('index.html','_self')</script>";
    }
}
?>

确定

您的文本输入具有相同的静态名称如果你想保存它,你必须给它一个数组名称:

<input type="text" name="mechanic_ID[]" value="first_one" />
<input type="text" name="mechanic_ID[]" value="second_one" />
and when get data
$mechanic_ids = $_POST['mechanic_ID'];
// this give you data in array ('first_one','second_one')
can resume 
foreach($mechanic_ids as $mechanic_id){
// do some thing in this one
}

这里是关于html和php数组的好例子

这里是可以检索到的机械表整体数据(mechanic_ID,mechanic_name),它显示了所有的数据;因为while循环,但是当注册它时,第一行只能发布,其余行不能发布。