0
votes

I'm getting this error when I'm trying to edit data using CodeIgniter.

My controller:

public function edit_data($kode_part)
{
$tabel_part = $this->model_tabel_part->get_tabel_part("where kode_part ='$kode_part'");

foreach($tabel_part->result_array()as $row){
$kode_part   = $row['kode_part'];
$nama_part   = $row['nama_part'];
$warna_part  = $row['warna_part'];
$cavity      = $row['cavity'];
$gross       = $row['gross'];
}

$data['kode_part']   = $kode_part;
$data['nama_part']   = $nama_part;
$data['warna_part']  = $warna_part;
$data['cavity']      = $cavity;
$data['gross']       = $gross;

$this->load->view('datamaster/tabel_part/v_edit_part', $data);

}

My Model:

public function get_tabel_part($where = ""){
$data_tabel_part = $this->db->query("select * from tabel_part".$where);
return $data_tabel_part;
}

And I'm getting this error:

A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '='34232-C0100'' at line 1

select * from tabel_partwhere kode_part ='34232-C0100'

Filename: C:/xampp/htdocs/tpidbv1.1/system/database/DB_driver.php

Line Number: 691

Can you find any thing wrong here?

2

2 Answers

0
votes

Your Error message is this...

select * from tabel_partwhere kode_part ='34232-C0100'

There is No Space between the table name and your "where" statement. So in your model you need to add in a space in your SQL...

So this...

$data_tabel_part = $this->db->query("select * from tabel_part".$where);

Becomes this...

$data_tabel_part = $this->db->query("select * from tabel_part ".$where); // Added Space
0
votes

Please add a space between the table name and the where clause.

public function get_tabel_part($where = ""){
    $data_tabel_part = $this->db->query("select * from tabel_part ".$where);
    return $data_tabel_part;
}