Jump to content

Alert Dialog Box


takeiteasy

Recommended Posts

can i ask if there's php code for displaying an alert dialog box?if there is. can anyone teach me how to code please?

i'm doing a delete function and i want to prompt the user if they really want to delete the record.
here is my delete code
[code]
if (isset($HTTP_GET_VARS['empRef']))
{
$result = mysql_query("DELETE FROM airticketbooking WHERE empRef = '$empRef'",$db_connection) or die(mysql_error());
mysql_close($db_connection);

}

if($result == true)
{
      echo "
'Record Deleted' ";
}
[/code]
Link to comment
Share on other sites

There is no way to do it in PHP. But you can with javascript. What you'll want to do is sometying like this:

Place this code just before the <head> tags on your script
[code]<script type="text/javascript">
function confirmDel()
{
    var del = confirm("Are you sure you wish to continue?\n\nClick Ok to continue");
    if (del) {
        return true;
    } else {
        return false;
    }
}
</script>[/code]

Now the link. The following will be what you link will look like:
[code]<a href="delete.php?id=$id" onclick="return confirmDel()">Delete</a>[/code]
Change where it says [i]delete.php?id=$id[/i] to where you actually send the user and dont forget to send the and id over the url so mysql deletes the correct data from mysql.

NOte the what how the code works is the onclick attribute. Notice that is says [i]return conformDel[/i]. What that does is it will only go to the delete.php page if and onlu of the confirmDel function returns true, otherwise it will not go any where, and thats how you create simple confirm box.
Link to comment
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.