> Ok, I am trying to add a "yes"/"no" dialog for a delete
operation and I was
> attempting this via the javascript "confirm" function, but
no matter if I
> click yes or no, the php code block still executes. I
tried this way:

It'll work...

> <script language="javascript">
> if(!confirm("Are you sure you wish to delete this section?
This will delete
> all llamas in this section as well!!")) {
> document.location.href="llama.php3";
> } else{
> <?php
>   $db = NewDatabase("MySQL", "fusion", "5xc7hn3",
"fusion", "localhost");
>   $db->open();
>   if(!$db->execute("delete from lf_llamas where lfl_lfs_id
= $id"))
> die(print $db->geterror() . " while deleting from
lf_llamas.");
>   if(!$db->execute("delete from lf_sections where lfs_id =
$id")) die(print
> $db->geterror() . " while deleteing from lf_sections.");
>   $db->close();
> ?>
> }
> document.location.href="llama.php3";
> </script>
> ---------------------------------------------------------
>
> thinking that the second code block would not be executed
if they clicked
> "no".

Think back to the order that this stuff is going to be
processed... PHP is server side, and the code is going to be
executed on the server before it even goes back to the
browser. Thus your db record will be deleted either way.

The way I do this is to create a JavaScript function on the
first page (the one with the buttons/links to delete stuff)
that looks something like this:

<script language="javascript">
function dbDelete(strDescription, itemId) {
    if (confirm('Warning:\n\nYou are about to delete ' .
strDescription . '.\n\nDo you wish to proceed?'))
        location.href='path/to/delete/file.php?id=' .
itemId;
}
</script>

And let file.php perform the deletion and return to where
ever is an appropriate return location.

> Does PHP have a native function for yes/no dialogs? I
searched the docs and
> couldn't find anything :(

It doesn't because it's processed server-side and not
client-side...

--Toby


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to