I have recently followed a tutorial playlist on PHP OOP by mmtuts on youtube, but he used PDO and I don't and I am getting an error when I try to implement the code in my project.
My code:
//In file with class 'Article'.
public function deleteArticle($id) {
$conn = $this->connect();
$sql = "UPDATE article SET deleted=1 WHERE row_id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
//In file with class 'DBConn'.
public function connect() {
$conn = new mysqli('localhost', 'root', '','nicms');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
return $conn;
}
//In file with class 'articleContr'.
public function showDeleteArticle($id) {
if ($this->deleteArticle($id)
echo "Article has successfully been deleted.";
else
echo "Failed to delete article.";
}
The error is that the article DOES get deleted but the method showDeleteArticle gives the message 'Failed to delete article'. even though the article has been deleted.