在此示例中,我们将通过CodeIgniter插入数据库中显示印度名称含义的不同值。
在application / controller中,将创建文件baby_form.php。
<?php
defined('BASEPATH') OR exit('No direct 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 database table.
$this->db->insert('baby',$data);
redirect("baby_form/index");
}
}
?>
看上面的快照,我们的表名是“ baby”。
<!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>
这是我们的视图页面,正在加载到控制器页面中。
要在浏览器上运行它,请传递URL
http://localhost/insert/index.php/Baby_form/
通过在上面的表格中插入各种名称,我们创建了表格,如下所示。
Made with ❤️ in Chengdu. Copyright reserved 2019-2023.
蜀ICP备20006366号-1