I am trying to create an HTML button, that, when pressed, it will truncate a MySQL table. I used the answer given here. The button works, but the problem is that when I refresh the page, the command is triggered and the table gets truncated, even though I have not pressed the truncate button. How can I fix that? I only have one .php file.
The code so far is:
<?php
$dbc = mysqli_connect('localhost', 'username', '', 'DB_name')
or die('Error connecting to MySQL server.');
?>
<form method="post" action="<?php mysqli_query($dbc, 'TRUNCATE TABLE `my_table`') ?>">
<input name="submit_button" type="submit" value=" Truncate Table " />
</form>
I would not consider my question as a duplicate, because in the other question, there is a redirection to an other .php page.