PHP/Javascript

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
kumarrana
Forum Commoner
Posts: 26
Joined: Sat Sep 01, 2007 12:55 pm

PHP/Javascript

Post by kumarrana »

This might not be the right place to ask my question. btw I have written a web-blog on PHP and MySQL. At the end I have realized that I don't have any warning message for user before they delete their account, or contents. I know it can be done on javascript but I don't know much about it. Can any body give me a sample code for pop-up message that can be send before user decide to delete their account?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP/Javascript

Post by Christopher »

You can do something simple with the standard Javascript dialogs:

http://www.w3schools.com/js/js_popup.asp

Or you can try something fancier with a popup div.
(#10850)
kumarrana
Forum Commoner
Posts: 26
Joined: Sat Sep 01, 2007 12:55 pm

Re: PHP/Javascript

Post by kumarrana »

Thanks for the tips.
Here is the part of the PHP and JavaScript code that I have been trying to make it work.

My javascript is (filename javapopups.htm)

Code: Select all

 
<script type="text/javascript">
<!--
document.write(confirmation());
function confirmation() {
    var answer = confirm(" Are you sure you want to delete?")
    if (!answer){
        window.location = "index.php";
    }
        document.write("Your content will be deleted!")
    <!--}
}
</script>
and I am trying to embed it into PHP code which looks like this

Code: Select all

 
if($_GET['what'] == delete_comm)
{
    include("javapopups.htm");
    echo $row_num = $_GET['which'];
    echo $row_num .  "<br>is row number ";
    $delete_comment = "DELETE FROM comment where commentid = $row_num";
    $delete_comment_query = mysql_query($delete_comment);
    if(!delete_comment_query)
    {   
        echo "Error on deleting ".mysql_error();
    } else
    {
        echo "Comment deleted! "; 
        echo "<meta http-equiv = \"refresh\" content = \"0; URL=index.php?page=$pageNum\">";
    }
}
 

My goal is to have user delete the comment if they click OK on pop up dialog box, and refresh the page if not. Bug is it deletes in both circumstances. Any idea?
kumarrana
Forum Commoner
Posts: 26
Joined: Sat Sep 01, 2007 12:55 pm

Re: PHP/Javascript

Post by kumarrana »

Please somebody help he in this issue.
Post Reply