2016-07-30 13 views
-1

ここで私はwhileループの問題に直面しています。(私は思う)私のすべてを格納することができない私のHTMLフォームにMySQLのテーブルからデータを取得します。私のすべてを格納することができませんMysqlテーブルからのデータを新しいHTMLフォームに取得します。

最初の行のみが掲載な​​っていると、行の残りの部分はwhileループから繰り返し取得、同じ名前の要素が原因で投稿されていない、

ここで$ _POST [「mechanic_name」];あなたはPLSのアドバイス

<?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>"; 
 
    } 
 

 
}

以下のコードを持つ他の問題を考える場合、これはwhileループ、鉱石ではありませんので、私は。これで何の問題.. を使用しています1時間!plzは私を助けて... `

答えて

0

OK

テキスト入力あなたのようにそれを保存したい場合、あなたはそれを配列名を与えるshuld 同じ静的な名前を持っている:

<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 
} 

ここに良い例についてarrays form html and php

+0

ok Homam Alhaytham。 –

+0

はい、@Homan Alhaytham、それは良いですありがとう.. しかし、私は1つのテーブルのデータ行の 'コード'値= "<?php echo $ mechanic_ID;?>からエコーしたので、" first_one "を追加しません"私はそれを1つのテーブルからロードします。 私はout value = "<?php echo $ mechanic_ID;で配列関数をテストしました。 ?>それは動作していますが、他のテーブルに格納できるデータをテーブルから取得する必要があります。 (ドロップダウンメニューで動作していますが)テーブル形式が必要です **太字**ここで私は 'メカニックテーブル'からエコーデータを取得し、それを 'スケジュールテーブル' –

0
ここ
<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>"; 
    } 

} 

?> 
0

である事がメカニックテーブル全体のデータ(mechsanic_ID、Mechanic_name)、それはすべてのデータを見せて取得することができます。 whileループのために、しかしそれを登録すると、最初の行は投稿でき、残りの行は投稿されませんinterface look like this

関連する問題