...

View Full Version : javascript and php



asherinho
08-23-2008, 07:21 PM
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


<?
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>";
?>

Philip M
08-23-2008, 08:00 PM
echo "if(answer) {

Arbitrator
08-24-2008, 06:52 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum