我們將在資料庫中插入不同的值 在應用程式/控制器中,創建檔案 baby_form.php。
<?php
defined('BASEPATH')OR exit('No diect script access allowed');
class Baby_form extends CI_Controller{
public function index(){
$this->load->view("baby_form_add");
}
function savingdata(){
//this array is used to get fetch data from the view page.
$data = array(
'name' => $this->input->post('name'),
'meaning' => $this->input->post('meaning'),
'gender' => $this->input->post('gender'),
'religion' => $this->input->post('religion')
);
//insert data into databse table.
$this->db->insert('baby',$data);
redirect("baby_form/index");
}
}
?>
查看檔案 (baby_form_add.php)
<!DOCTYPE html>
<html>
<head>
<title>Baby Form Add</title>
</head>
<body>
<form method="post" action="<?php echo site_url('baby_form/savingdata'); ?>">
<table>
<tr>
<td>Name:</td>
<td>:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Meaning:</td>
<td>:</td>
<td><input type="text" name="meaning"></td>
</tr>
<tr>
<td>Gender:</td>
<td>:</td>
<td><input type="text" name="gender"></td>
</tr>
<tr>
<td>Religion</td>
<td>:</td>
<td><input type="text" name="religion"></td>
</tr><br><br>
<tr>
<input type="submit" name="submit" value="Save">
</tr>
</table>
</form>
</body>
</html>
遇到未捕獲的例外型別:錯誤
訊息:呼叫未定義的函式 site_url()
檔案名:C:\xampp\htdocs\codeigniter3\application\views\baby_form_add.php
行號:9
uj5u.com熱心網友回復:
您的實際錯誤是 site_url() 未定義。在您的控制器中使用URL 輔助函式。
$this->load->helper('url');
有關更多資訊,您可以查看以下與“URL 助手”相關的 URL。
http://codeigniter.com/user_guide/helpers/url_helper.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/497859.html
上一篇:如何比較陣列php中的值
