控制器不工作時:Purchase.php提交按鈕插入表單值
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Purchase extends CI_Controller
{
function __construct()
{
parent:: __construct();
$this->load->model('purchase_data');
}
public function add_product_master()
{
if($this->input->post('submit'))
{
$data = array(
'product_name'=> $this->input->post('product_name'),
'category'=> $this->input->post('category'),
'sub_category'=> $this->input->post('sub_category'),
'description'=> $this->input->post('description'),
);
$query = $this->db->insert('product_master',$data);
if($query == true)
{
$this->session->set_flashdata('message', '<p style="color: green;font-weight: bold;">Your product added successfully.</p>');
echo "<meta http-equiv='refresh' content='1'>";
}
else
{
$this->session->set_flashdata('message', '<p style="color: red;font-weight: bold;">Error!</p>');
}
}
$this->load->view('product-master');
}
}
視圖:產品master.php
<?php echo $this->session->flashdata('message');?>
<form class="form-horizontal form-label-left" method="post">
<input type="text" name="product_name" id="product_name" required="required" />
<input type="text" name="category" id="category" required="required" />
<input type="text" name="sub_category" id="sub_category" required="required" />
<textarea name="description" id="description" required="required"></textarea>
<input type="submit" name="submit" id="submit" class="btn btn-success" value="submit">
</form>
我已創建具有名稱產品master.php的形式。但是當我點擊提交按鈕時,它不會插入表單值或不顯示任何flash數據消息不知道爲什麼。那麼,我該如何解決這個問題?請幫幫我。
謝謝
您需要添加動作才能形成標籤。
您是否收到任何錯誤? –
添加行動方法在窗體標籤@omkara –