Page 1 of 1

form still deleting mysql result after canceling 'confirm'

Posted: Sat May 09, 2009 7:42 am
by tomsace
Hi,

I have tried to add a message when the submit button is clicked when deleting a result from mysql.
The message appears but if I click cancel the form still deletes the entry anyway!! This must be something wrong on the php side of the script but I just cant put my finger on it...

Heres my code:

Code: Select all

<?php
if($_POST['Delete']){
$query = "DELETE FROM games WHERE id = '$id'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error()); }{ ?>
<form method="post" action="">
<input type="image" src="images/btn_delete.jpg" name="Delete" value="Delete" onClick="if(confirm('Are you sure you want to delete this game?')) document.test_form.submit();"></form>
<?php } ?>

Re: form still deleting mysql result after canceling 'confirm'

Posted: Sat May 09, 2009 8:22 am
by Defiline

Code: Select all

<script type="text/javascript">
 
function DeleteField()
{
    if(comfirm('Are you sure?')) {
        return true;
    }else{
        return false;
    }
}
 
</script>

Code: Select all

<form method="post" action="">
    <input type="image" src="images/btn_delete.jpg" name="Delete" value="Delete" onClick="return DeleteField();">
</form>
If you do not want to submit the form, "return" value must be false.
JavaScript side.

Re: form still deleting mysql result after canceling 'confirm'

Posted: Sat May 09, 2009 9:16 am
by tomsace
Oh right now I see.
Thanks alot you got it working perfectly!