Setup: HTML form with delete button.
Issue: After I press the delete button the data on the page doesnt get refreshed. If I reload the page the data is corrected. I know there is a header script to use in here but i was looking for an alternate option. Heres my code
<?php
include("dbCONNECT.php");
//Contains Database Connection information
echo "Article Table Contents </br></br></br>";
$query = "select * from articles";
$result=mysql_query($query);
$num = mysql_numrows($result);
echo "Index Title</br> ";
$i = 0;
while ($i<$num)
{
$index = mysql_result($result,$i,"primindex");
$title = mysql_result($result,$i,"Title");
echo "$index $title </br> ";
$i++;
}
echo " </br> </br> </br> </br> ----------------Delete option below----------------- </br> </br> </br>";
?>
<form action="tableContents.php" method = "POST">
<table>
<tr>
<td> Index of article to be deleted</td>
<td><input type = "text" name="articleIndex" ></td>
</tr>
<tr>
<td></td>
<td><input type ="submit" name = "deleteENTRY" value ="Delete Article"></td>
</tr>
</table>
</form>
<?php
$indexEntered = $_POST['articleIndex'];
if($_POST['deleteENTRY']) //checks if form input has been posted
{
echo "</br> delete button clicked";
$sql2="Delete from articles where primindex = ('" . $_POST['articleIndex'] . "');";
mysql_query($sql2);
echo "</br>Article with index of " . $_POST['articleIndex'] . " was deleted successfully . </br>" ;
// }//close else
}//end if POST
mysql_close();
?>