Hi I am getting PDO Exception, am i doing something wrong ? I tried to use the same query to insert data in PhpMyAdmin and it works though.
Error :Type: PDOException Code: 42000
Message: SQLSTATE[42000]: Syntax error or access violation: 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 '' at line 1 File: X:\SproutTech\Fashion-Blog\cms\app\Models\Post.php Line: 36
try {
$statement = $this->connection->prepare("INSERT INTO posts(title,content,image_path,tags,author,status,cat_id) VALUES(:title,:content,:image_path,:tags,:author,:status,:cat_id");
$statement->execute(array( ":title"=>$array['title'],
":author"=>$array['author'],
":content"=> $array['content'],
":image_path"=>$array['image_path'],
":tags"=>$array['tags'],
":status"=>$array['status'],
":cat_id"=>$array['cat_id'], ));
} catch (PDOException $e) {
echo $e->getMessage();
}
,after":cat_id"=>$array['cat_id']. remove it, rest looks fine to me. Also try once$statement->execute(array(":title"=>$array['title'],":content"=> $array['content'], ":image_path"=>$array['image_path'],":author"=>$array['author'],":status"=>$array['status'],":tags"=>$array['tags'],":cat_id"=>$array['cat_id']));(I don't think sequence change is the issue here,but it's a proper way to put things in exact sequence) - Anant Kumar Singh