我試圖插入數據到數據庫中,並且我的代碼添加了一個新行但所有值爲空。我不知道是什麼原因造成的。該視圖是在html中的模式。這裏是我的代碼:感謝您的幫助插入在codeigniter中不能正常工作
控制器:
public function addItem(){
$save = array(
'inventoryID' => $this->input->post('rfid'),
'masterCode' => $this->input->post('masterCode'),
'itemName' => $this->input->post('itemName'),
'colorName' => $this->input->post('colorName'),
'location' => $this->input->post('location'),
'itemCategory' => $this->input->post('itemCategory'),
'materialDescription' => $this->input->post('materialDescription'),
'supplier' => $this->input->post('supplier'),
'itemDescription' => $this->input->post('itemDescription'),
'comments' => $this->input->post('comments'),
'itemCode' => $this->input->post('itemCode'),
'colorCode' => $this->input->post('colorCode')
);
$this->searchModel->form_insert($save);
//load the header
$this->load->view('base.php',$save);
//load the page
redirect('Search');
//load the footer
$this->load->view('footer.php',$save);
}
型號:
功能form_insert($數據){
// Inserting in Table(inventory) of Database(library)
$this->load->database();
$this->db->insert('inventory', $data);
$inventoryID = $this->db->insert_id();
}
查看:
<div id="addItem" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<form method ="post" action= "<?php echo site_url("Search/addItem"); ?>">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Add an Item</h4>
</div>
<div class="modal-body">
<form role="form">
<table>
<tr>
<td><input type="text" name="rfid" placeholder="RFID" required/></td>
<td><input type="text" name="itemCode" placeholder="Item Code" required/></td>
<td><input type="text" name="masterCode" placeholder="Master Code" /></td>
</tr>
<tr>
<td><input type="text" name="itemName" placeholder="Item Name" required/></td>
<td><input type="text" name="colorCode" placeholder="Color Code" /></td>
<td><input type="text" name="colorName" placeholder="Color Name" /></td>
</tr>
<tr>
<td><input type="text" name="location" placeholder="Location" required/></td>
<td><input type="text" name="makelocation" placeholder="Location Made" required/></td>
<td><input type="text" name="itemCategory" placeholder="Item Category" /></td>
</tr>
<tr>
<td><input type="text" name="materialDescription" placeholder="Material Description" /></td>
<td><input type="text" name="supplier" placeholder="Supplier/Vendor" required/></td>
<td><input type="text" name="checkoutAllowed" placeholder="Checkout Allowed" /></td>
</tr>
</table>
<div class="row personal-info">
<div class="col-sm-4">
<div class="form-group">
<textarea name="itemDescription" placeholder="Insert information regarding the weather this item is suitable for and where it is used"></textarea>
<textarea name="Comments" placeholder="Additional Coments on the Item"></textarea>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer" style="text-align:center;">
<a href="<?php echo site_url("Search/addItem") ?>"><input class="btn btn-primary" name="addItem" value="Add Item"></a>
</div>
</form>
</div>
</div>
</div>
喜,首先鴕鳥政策需要添加標籤' 「>'之前'<輸入類=」 BTN btn-primary「name =」addItem「value =」添加項目「>'只替換爲'因爲你正在將'search/addItem'作爲正常鏈接重定向。然後,在插入數據庫之前,需要使用庫驗證輸入** form_validation ** – elddenmedio
public function addItem(){print_r($ this-> input-> post()); die(); 然後檢查 –
表中的列名稱是什麼? –