i've got an error saying "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use" i'm still new to codeigniter and i really need help currently this is the code that i've been trying to apply
function save() {
$reporter=$this->Settings_m->greporter();
$jabrik=$this->Settings_m->gjabrik();
$redpel=$this->Settings_m->gredpel();
$usertxt="";
if (in_array($this->session->userdata('ugroup'), $reporter )) {
$usertxt=",reporter=".$this->user.",reporter_time=now()";
}
if (in_array($this->session->userdata('ugroup'), $jabrik )) {
$usertxt=",jabrik=".$this->user.",jabrik_time=now()";
}
if (in_array($this->session->userdata('ugroup'), $redpel )) {
$usertxt=",redpel=".$this->user.",redpel_time=now()";
}
/* end for usertxt call */
if($this->input->post('pub') == 1){
if($this->input->post('tglpub') == "0000-00-00 00:00:00" || $this->input->post('tglpub') == ""){
$tgl=",publish_up=now()";
}else{
//$tgl = $this->input->post('tglpub');
$tgl = ",publish_up='".$this->input->post('tglpub')."'";
}
}else{
$tgl=",publish_up=''";
}
$title =str_replace('"',"'",$this->input->post('title'));
$query=" insert gis_news_items set "
.' title="' .$title.'"'
.",alias='" . $this->input->post('alias',true )."'"
.",introtext='". $this->input->post('content')."'"
.",fulltexts=' '"
.",catid=".$this->input->post('catid')
.",published=".$this->input->post('pub')
// .",hl=".$this->input->post('hl')
// .",focus=".$this->input->post('fcs')
// .",byline=".$byline
.$usertxt
.",modified_by=" . $this->user
// .",publish_up='" .$this->input->post('tglpub')."'"
.$tgl
.',metadesc="' . str_replace('"',"'", $this->input->post('deskripsi',true) ) .'"'
.',metakey="' . str_replace('"',"'", $this->input->post('keyword',true) ) .'"' ;
$this->M_general->add_data("gis_news_items", $query);
}
edit
this is the data that i got from the query i ran, i tried to tweak it using the suggestions here as reference but i still got the error, so i undo it to see the error
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 'insert into gis_news_items values ( title="sepatu nike 5m",alias='sepatu-nike-5' at line 1
INSERT INTO `gis_news_items` ( insert into gis_news_items values ( title="sepatu nike 5m",alias='sepatu-nike-5m',introtext='
sepatu nike seharga 5m dengan desain indomie
',fulltexts=' ',catid=586,published=0,modified_by=1150,publish_up='',metadesc="sepatu desain indomie",metakey="sepatu, indomie") VALUES ('')
any help and explanation would be appreciated since i'm still learning how to code a good query
thank you :)
You have invalid SQL query.
$query=" insert gis_news_items set "
should be
$query=" insert into gis_news_items values( "
....
checkout more examples here https://mariadb.com/kb/en/library/insert/
Try the sql
$query=" insert gis_news_items (title, alias, introtext, fulltexts, catid, published, modified_by, metadesc, metakey ) values
('".$title."', '".$this->input->post('alias',true )."', '". $this->input->post('content')."',' ', ".$this->input->post('catid').", '".$this->input->post('pub').$usertxt."', ".$this->user.$tgl.", '".str_replace('"',"'", $this->input->post('deskripsi',true) )."', '".str_replace('"',"'", $this->input->post('keyword',true) )."' ) ";