Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript and php

    hi! I have a php script page which performs the deletion of data to the mysql database,but I want first the user to confirm if he/she wants to delete the information by using javascript confirm message box.The challenge is,how can I make it in such a way that,if user clicks ok on the confirm message box then the php code for deletion should be executed and if the cancel button is clicked user should be directed to another page.Here is what I tried but it failed
    PHP Code:
    <?
     
    echo "<script language=javascript>";
     echo 
    "var answer=confirm('Delete user ".$usrname."?')";
     echo 
    "if(answer==1){";
    $result=mysql_query("DELETE FROM login WHERE uname='".$usrname."');
    $result2=mysql_query(\"DELETE FROM users WHERE username='"
    .$usrname."')";
     echo 
    "}else{window.location=('user_control.php')}</script>";
    ?>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    echo "if(answer) {

  • #3
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,302
    Thanks
    28
    Thanked 276 Times in 270 Posts
    Quote Originally Posted by asherinho View Post
    The challenge is,how can I make it in such a way that,if user clicks ok on the confirm message box then the php code for deletion should be executed and if the cancel button is clicked user should be directed to another page.
    Create a form with client‐side scripting that sets a hidden form field depending upon what option the user selects. Then submit the form to some address. Have the PHP at that address read the data passed from the hidden form field and react accordingly.
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •