Please help in my code to insert data to database it return with error
A PHP Error was encountered Severity: Notice Message: Undefined variable: computerName Filename: models/add_model.php Line Number: 20
View:
<form action="<?php echo base_url();?>index.php/speed/insert_into_db" method="post">
Branch: <input type="text" name="branch" /><br/>
Business Unit: <input type="text" name="buinessUnit" /><br/>
Device Type: <input type="text" name="deviceType" /><br/>
Brand: <input type="text" name="brand" /><br/>
Device Model: <input type="text" name="deviceModel" /><br/>
SN: <input type="text" name="SN" /><br/>
status: <input type="text" name="status" /><br/>
department: <input type="text" name="department" /><br/>
username: <input type="text" name="username" /><br/>
notes: <input type="textarea" name="notes" /><br/>
computername: <input type="text" name="computerName" /><br/>
Save:<input type="submit" name="save" />
</form>
model:
public function insert_into_db() {
if(isset($_POST['save'])) {
$branch = $_POST['branch'];
$buinessUnit = $_POST['buinessUnit'];
$deviceType = $_POST['deviceType'];
$brand = $_POST['brand'];
$deviceModel=$_POST['deviceModel'];
$SN = $_POST['SN'];
$status = $_POST['status'];
$department = $_POST['department'];
$username = $_POST['username'];
$notes = $_POST['notes'];
$computerName = $_POST['computerName'];
}
$this->db->query("INSERT INTO `hardware_assets`(`Branch`, `Business Unit`, `Device Type`, `Brand`, `Device Model`, `SN`, `Status`, `Departmant`, `UserName`, `Notes`, `Computer Name`)
VALUES ('$branch','$buinessUnit','$deviceType','$brand','$deviceModel','$SN','$status','$department','$username','$notes','$computerName')");
}
}
Controller:
<?php
class Speed extends CI_Controller {
public function view($page = 'home')
{
// if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php'))
// {
// // Whoops, we don't have a page for that!
// show_404();
// }
// $data['title'] = ucfirst($page); // Capitalize the first letter
// $this->load->view('templates/header', $data);
// $this->load->view('pages/'.$page, $data);
// $this->load->view('templates/footer', $data);
// }
function insert_to_db(){
$this->load->model('add_model');
$this->add_model->insert_into_db();
$this->load->view('pages/home');//loading success view
}
}