-1

Hi I'm make form for add row in my php and want to insert for the database. But I don't know how to passing that multiple row from my php page into my database could you explain me and give me the solution for my problem? maybe I'll show my code for understand

form php :

<div class="box box-primary">
  <div class="box-header">
    <h3 class="box-title">Detail Modules</h3>   
    <input class="btn btn-danger btn-flat pull-right" type="button" value="Delete Modules" onClick="deleteRow('dataTable')" />
    <input class="btn btn-info btn-flat pull-right" type="button" value="Add Modules" onClick="addRow('dataTable')" />
  </div>
  <div class="box-body">
    <div class="form-group">
      <table id="dataTable" class="table table-hover table-bordered">
        <tbody>
          <tr>
            <td width=10 align=center><input type="checkbox" name="chk[]" class="minimal"/></td>
            <td>
              <label for="jenis_modules">Modules</label>
              <select name="jenis_modules[]" type="text" id="jenis_modules" class="form-control">
                <option value="" disabled selected>Choose Modules</option>
                <option value="GL">General Ledger</option>
                <option value="AR">Account Receivable</option>
                <option value="AP">Account Payable</option>
                <option value="FA">Fixed Assets</option>
                <option value="CM">Cash Management</option>
                <option value="P">Purchasing</option>
                <option value="I">Inventory</option>
                <option value="OM">Order Management</option>
                <option value="FS">Fields Services</option>
                <option value="In">Integrasi</option>
              </select>
            <?php echo form_error('jenis_modules'); ?>
            </td>
            <td>
              <label for="descrip">Description</label>
              <input id="desc" class="form-control" type="text" name="desc[]" maxlength="200"/>
            <?php echo form_error('desc'); ?>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</div>

and my process :

$modules = $this->input->post('jenis_modules');
$description = $this->input->post('desc');  
$save = mysql_query("INSERT INTO master_projects_line 
                         (project_id, modules, description)
                       VALUES
                         ('$project_id', '$modules', '$description')");
Darwin von Corax
  • 5,201
  • 3
  • 17
  • 28

2 Answers2

0

Just use implode to convert array in to string and use MYSQLI MYSQL is depreciated.

You have only one description textarea so change name of textarea desc[] to desc if you still want to use as desc[] then use $description[0] in insert query.

$conn = mysqli_connect("localhost","my_user","my_password","my_db");
$modules = implode(',',$this->input->post('jenis_modules'));
$description = $this->input->post('desc');  
$save = mysqli_query($conn,"INSERT INTO master_projects_line 
                     (project_id, modules, description)
                   VALUES
                     ('$project_id', '$modules', '$description')");
Vinie
  • 2,983
  • 1
  • 18
  • 29
0

Hope It helps.

$chk=$this->input->post('chk');
$modules = $this->input->post('jenis_modules');
$description = $this->input->post('desc');  
foreach($chk as $key=>$val){
     $modules=$modules[$key];  
     $description=$description[$key];
     $save = mysql_query("INSERT INTO master_projects_line 
                         (project_id, modules, description)
                         VALUES
                         ('$project_id', '$modules', '$description')");
}
dhruv jadia
  • 1,684
  • 2
  • 15
  • 28