Reputation:
Everthing seems to be working properly on my code, but when i want to add a new subject,i fill the different fields, i click on the "save" button AND i got this error:
A Database Error Occurred
Error number: 1054
Unknown column 'carrera' in 'field list'
INSERT INTO `materias` (`carrera`, `materia`, `descripcion`, `carga_horaria`) VALUES ('5', 'Calculus', 'dfsfsdfsd', '2')
Filename: C:/xampp/htdocs/NUEVO_PROJECTO/crud/system/database/DB_driver.php
Line Number: 691
I was given 2 tables: "materias" and "carreras"
"materias" includes (id, carrera_id (is the foreign key to the column "id" of the table "carreras") nombre, descripcion, carga_horaria)
"carreras" includes (id,nombre,descripcion).
Here is my controller file (with the save function only):
public function save() {
$txtcarr = $this->input->post("txtcarr");
$txtmat = $this->input->post("txtmat");
$txtdesc = $this->input->post("txtdesc");
$txtcarga = $this->input->post("txtcarga");
$this->Crudmodel->save($txtcarr, $txtmat, $txtdesc, $txtcarga);
redirect('Home/index');
}
Here is my crudmodel file (with the save function only):
public function save($txtcarr, $txtmat, $txtdesc, $txtcarga) {
$data = array(
'carrera' => $txtcarr,
'materia' => $txtmat,
'descripcion' => $txtdesc,
'carga_horaria' => $txtcarga
);
$this->db->insert('materias', $data);
}
And my "ADD" function:
<?php include('footer.php'); ?>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2 align="center">AGREGAR MATERIA</h2>
<form method="post" action='<?php echo site_url('Home/save'); ?>'>
<tr>
<td>
<select name="txtcarr">
<?php foreach($carreras as $item):?>
<option value="<?php echo $item->id;?>"><?php echo $item->nombre;?></option>
<?php endforeach;?>
</select>
</td>
</tr>
<tr>
<td>Materia : </td>
<td><input type="text" name="txtmat"/></td>
</tr>
<tr>
<td>Descripcion : </td>
<td><textarea name="txtdesc"></textarea></td>
</tr>
<tr>
<td>Carga horaria : </td>
<td><input type="text" name="txtcarga" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="save" /></td>
</tr>
<table class="table table-hover" align="center" border="0" cellspacing="0" cellpadding="0" width="300">
</table>
</div>
</div>
</div>
Hope you can help me!
Upvotes: 0
Views: 93
Reputation: 229
This error means that you don't have column "carrera" in your table, so you need add it to your table in datatbase or maybe you have spelling mistake there.
Upvotes: 1