![]() |
having issues with Error Number: 1064 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: having issues with Error Number: 1064 (/showthread.php?tid=62107) |
having issues with Error Number: 1064 - xiaolee - 06-10-2015 any time i try to access a page i created it says:Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 SELECT * FROM (`_db_tb_article`) WHERE `article_id` = Filename: C:\xampp\htdocs\gtech\__ghtec__$y$tem__core\database\DB_driver.php Line Number: 330 this is my model <?php class article_model extends CI_Model { function add() { $this->db->insert('article',$_POST); if($this->db->_error_number()) { return $this->db->_error_number(); } } function update($article_id, $data_fields = NULL){ if($data_fields == NULL) { $this->db->where("article_id =".$article_id); $this->db->update('article',$_POST); } else { $this->db->where("article_id =".$article_id); $this->db->update('article',$data_fields); } $is_error = $this->db->_error_number(); if($is_error){ echo $is_error; } return TRUE; } function delete($id){ $this->db->where("article_id =".$id); return $this->db->delete('article'); } //return the article with this id function get_article($id){ $this->db->where("article_id =".$id); $query = $this->db->get('article'); if ($query->num_rows() > 0){ return $query->row_array(); } else echo $this->db->_error_message(); return FALSE; } //return the available article in the table function get_article_all(){ $query = $this->db->get('article'); if ($query->num_rows() > 0) { foreach($query->result() as $row) { $result[] = $row; } return $result; } } } i have checked the line 330 and can't seem to find a way to solve that problem....i need help RE: having issues with Error Number: 1064 - RogerMore - 06-10-2015 Hey xiaolee, welcome to the forum. Are you sure you are calling get_article with an id like get_article(22)? I tried to sabotage a query of mine by leaving the id empty and I got the very same SQL error. Maybe you can add a temporarily var_dump() to your function like so: PHP Code: function get_article($id){ This will display the contents of $id. If there is no contents, your query will miss the id of the article you're trying to load which tells you your call to get_article is wrong. Hope this helps! -Roger RE: having issues with Error Number: 1064 - xiaolee - 06-10-2015 (06-10-2015, 07:28 AM)RogerMore Wrote: Hey xiaolee, welcome to the forum. RE: having issues with Error Number: 1064 - mwhitney - 06-10-2015 As @RogerMore mentioned, you need to check your inputs. There may be a few other issues in there, too. PHP Code: <?php RE: having issues with Error Number: 1064 - xiaolee - 06-10-2015 thanks, but now i have another problem, anytime i go to the view and click the link I pathed to the add function it just refreshes the page... i made the link something like... <div style="float:right"><a href="javascript:load_content('index.php/article/add')"> Add</a></div> what should I do to solve that.... RE: having issues with Error Number: 1064 - mwhitney - 06-10-2015 At best, that link is just going to do whatever your load_content() function tells it to do in your JavaScript. You would be better off creating a form with Code: <?php form_open(site_url('article/add')); ?> It's always best to take these things one step at a time. If the form works, you'll know that your HTML/view, controller, and model are working. Once that's done, you add JavaScript to change the button/form behavior to do the same thing via AJAX, and you shouldn't have to troubleshoot anything other than the script (as long as you leave everything else alone). Further, you gain the benefit of the form continuing to work if someone disables the script. |