form still deleting mysql result after canceling 'confirm'

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

form still deleting mysql result after canceling 'confirm'

Post 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 } ?>
Defiline
Forum Commoner
Posts: 59
Joined: Tue May 05, 2009 5:34 pm

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

Post 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.
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

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

Post by tomsace »

Oh right now I see.
Thanks alot you got it working perfectly!
Post Reply