Page 1 of 1

PHP/Javascript

Posted: Fri Mar 21, 2008 2:05 am
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?

Re: PHP/Javascript

Posted: Fri Mar 21, 2008 5:19 am
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.

Re: PHP/Javascript

Posted: Sat Mar 22, 2008 12:59 am
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?

Re: PHP/Javascript

Posted: Thu Apr 10, 2008 3:34 pm
by kumarrana
Please somebody help he in this issue.