[英]sql syntax error when inserting into database codeigniter
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 我遇到一个错误,说“您的SQL语法有错误;请查看与您的MariaDB服务器版本相对应的手册以使用正确的语法”。我对Codeigniter还是陌生的,目前我真的需要帮助,这是我一直尝试应用的代码
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. 您有无效的SQL查询。
$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/ 在此处查看更多示例https://mariadb.com/kb/zh/library/insert/
Try the sql 试试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) )."' ) ";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.