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