I'm looking for a way to clean my DB with a button on a html-page (.php). I have a code that's working OK, but every time I go in to the page the function is cleaning my DB without me pushing the button.
Here is my code
<button id="checkoutbutton" onclick="cleanDb()">Clean DB</button>
<script>
function cleanDb()
{alert("<?php clean();?>")}
</script>
<?php
function clean()
{
$con=mysql_connect("localhost","rss","Habb0") or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db("kalender",$con) or die("Failed to connect to MySQL: " . mysql_error());
$sql='DELETE FROM `bilder` WHERE `stop` < now()';
mysql_query($sql);
echo "Databasen är rensad från gamla bilder";}
?>
Please help me!