2017-01-18 4 views
2

複数の行を1つずつ追加できるフォームテーブルを作成しました 送信ボタンにすべての行のデータを挿入します。私はここSQLiに複数の行を追加するにはどうすればよいですか?

が私のHTMLコードである私の複数の行からのみ単一行つまり一番上の行を追加することができる午前:ここ

<div class = "table-responsive"> 
     <table class="table table-responsive table-striped table-bordered table-condensed "> 
    <thead> 
    <tr> 
     <th class="text-center">#</th> 
     <th>Name Of DE</th> 
     <th>Game Plan Posted</th> 
     <th>Patch Name </th> 
     <th>Summary</th> 
     <th>P.O.B</th> 
     <th>Dr. Conversion </th> 
     <th>Remarks </th> 
    </tr> 
    </thead> 
    <tbody id="dataTable"> 
    <tr> 
     <td><input type="checkbox" name="chk[]" /></td> 
     <td><input type = "text" name = "de[]"></td> 
     <td> 
     <select id="gamePlan" name="gamePlan[]"> 
      <option>----- Select ------</option> 
      <option>Yes</option> 
      <option>No</option> 
      </select> 
     </td> 
     <td><input type = "text" name = "patch[]"></td> 
     <td> 
     <select id="summary" name="summary[]"> 
      <option>----- Select ------</option> 
      <option>Yes</option> 
      <option>No</option> 
      </select> 
     </td> 
     <td><textarea type="textarea" name= "pob[]"></textarea></td> 
     <td><input type = "text" name = "drc[]"></td> 
     <td><input type = "text" name = "rem[]"></td> 

    </tr> 

    </tbody> 
</table> 
</div> 

は私のPHPコードです:

<?php 
    if(isset($_POST['submit'])){ 
foreach($_POST['de'] as $k => $name) { 
    $na =$db->escape($_POST['de'][$k]); 
    $pa =$db->escape($_POST['patch'][$k]); 
    $pob = $db->escape($_POST['pob'][$k]); 
    $dr = $db->escape($_POST['drc'][$k]); 
    $re = $db->escape($_POST['rem'][$k]); 
    $game = $db->escape($_POST['gamePlan'][$k]); 
    $sum = $db->escape($_POST['summary'][$k]); 

    // coqueryntinue insertion 
    $query = "INSERT INTO misrep(DE, game_plan, patch_name, summary, pob, dr_conversion, remark) 
      VALUES('$na', '$game', '$pa', '$sum','$pob','$dr', '$re')"; 

     if($db->query($query)){ 
    $session->msg('s',"Product added "); 
    redirect('tbl_report.php', false); 
} else { 
    $session->msg('d',' Sorry failed to added!'); 
    redirect('product.php', false); 
} 

    } 

}

それを解決するのを手伝ってください!おかげ

+3

最初の挿入後にリダイレクトを行う理由は何ですか? –

+0

@YourCommonSense Thnx素晴らしいキャッチ、ちょうど作業完璧を削除!もう一度過ごす –

答えて

0

そのような変更を:

if(isset($_POST['submit'])){ 
    foreach($_POST['de'] as $k => $name) { 
    $na =$db->escape($_POST['de'][$k]); 
    //paste rest of your bind code here 
    $values [] = "('$na', '$game', '$pa', '$sum','$pob','$dr', '$re')"; 
    } 
    $query = "INSERT INTO misrep(DE, game_plan, patch_name, summary, pob, dr_conversion, remark) 
     VALUES " .implode(', ',$values); 
    if($db->query($query)){ 
    $session->msg('s',"Products added "); 
    redirect('tbl_report.php', false); 
    } else { 
    $session->msg('d',' Sorry failed to added!'); 
    redirect('product.php', false); 
    } 
} 

あなたはすべての製品を挿入したい場合は、1つのクエリを聖霊降臨祭。

0

@ Your Common Sense感謝の残りの部分は、リダイレクト以外は正しいです。私はリダイレクト方法を削除しました。今は完璧に動作しています ありがとう

関連する問題