I have problems with deleting a record from the screen using MSQLI.
Here you can see the code i’m using.
<?php
include_once("assets/classes/connection.php");
include_once("assets/classes/article.class.php");
while($test = $allArticles->fetch_assoc())
{
if($test['titel']=="")
{
echo "<div class='zonderfoto'>";
echo "<h5>"."geen titel hier, aparte opmaak geslaagd" . "<br /></h1>";
echo "<p>" . $test['article'] . "</p>";
echo "<input type='submit' name='verwijderee' value='verwijder'>";
echo "</div>";
}
else
{
echo "<div class='metfoto'>";
echo "<h1>".$test['titel'] . "<br /></h1>";
echo "<p>" . $test['article'] . "</p>";
echo "<form method='post' action=''>";
echo "<input type='submit' name='verwijder' value='verwijder'>";
echo "</form>";
echo "<h1>".$test['id']."</h1>";
echo "</div>";
}
}
$vArticle = new Article;
$vArticle -> Key = $test['id'];
if (isset($_POST['verwijder']))
{
$vArticle -> deleteArticle();
echo ("shit");
}
?>
I’m using a while function to print all the DB records on the screen. The if function is just a function to give some design with css so nothing more. With the delete button i want to delete the record from the screen. With the $test[‘id’] variabele you receive the ID of the record in the DB
Ok here is my code from the class.
public function deleteArticle()
{
include("connection.php");
$sSql = "DELETE FROM tblArticles WHERE id = '".$this->m_sKey."'";
if (!$mysqli -> query($sSql))
{
throw new Exception("Something went wrong");
}
}
EDIT
There is something wrong with the key, i replaced the where statement with title =””, so i deleted one title in the database, and when i click on delete then, he delete one row, but this is not happening at runtime. so i click delete, one row deleted, BUT the content only dissapear with a page refresh. The solution is using ajax?
1 Answer