we will INSERT different values in database In application/controller, file baby_form.php is created.
<?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");
}
}
?>
View file (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>
An uncaught Exception was encountered Type: Error
Message: Call to undefined function site_url()
Filename: C:\xampp\htdocs\codeigniter3\application\views\baby_form_add.php
Line Number: 9
CodePudding user response:
your actual error is site_url() is undefined. Use the URL helper function in your controller.
$this->load->helper('url');
For More information, you can check the following URL related to "URL helpers".