joakoman Posted December 7, 2012 Share Posted December 7, 2012 Hi, i'm developing a module that inserts rows on the db, but the query always returns false and I have no idea why... i've tried everything and it's still not working Here's the function: public function getContent() { if (Tools::isSubmit('submit')) { $title = Tools::getValue("title"); $category = Tools::getValue("category"); if(Tools::getValue("visible") == "on"){ $visible = 1;}else{ $visible = 0; } $notice = Tools::getValue("newMessage"); $image = Tools::getValue("image"); $db = Db::getInstance(); $sql = 'INSERT INTO `'._DB_PREFIX_.'blog` (`title`, `image`, `category`, `notice`, `visible`) VALUES ('.$title.', '.$image.', '.$category.', '.$notice.', '.$visible.')'; if($db->execute($sql)) echo "good"; else echo "error"; } $this->_displayForm(); return $this->_html; } any idea? Thanks in advance! Link to comment Share on other sites More sharing options...
Burhan BVK Posted December 7, 2012 Share Posted December 7, 2012 Your text fields are not quoted (") and not escaped. Link to comment Share on other sites More sharing options...
joakoman Posted December 7, 2012 Author Share Posted December 7, 2012 mm I changed it to : $sql = "INSERT INTO '"._DB_PREFIX_."blog' ('title', 'image', 'category', 'notice', 'visible') VALUES (".$title.", ".$image.", ".$category.", ".$notice.", ".$visible.")"; but nothing happens, what do you mean by escaping them? could you correct the sentence for me? Thanks! Link to comment Share on other sites More sharing options...
akshik Posted December 13, 2012 Share Posted December 13, 2012 (edited) Hello Joakoman, you have to put the text(string) data into quotes(either single or double) and integer data without any quotes. So from your query I'm assuming that your title,image,category, notice fields are going to take text data and visible a boolean field Based on this your query can be written in the following way $sql = "INSERT INTO "._DB_PREFIX_."blog (title, image, category, notice, visible) VALUES ('$title', '$image', '$category', '$notice', $visible)"; Also table fields come without any quotations Edited December 14, 2012 by akshik (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now