Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-23-2008, 07:21 PM   PM User | #1
asherinho
New to the CF scene

 
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
asherinho is an unknown quantity at this point
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>";
?>
asherinho is offline   Reply With Quote
Old 08-23-2008, 08:00 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
echo "if(answer) {
Philip M is offline   Reply With Quote
Old 08-24-2008, 06:52 AM   PM User | #3
Arbitrator
Senior Coder

 
Arbitrator's Avatar
 
Join Date: Mar 2006
Location: Splendora, Texas, United States of America
Posts: 2,895
Thanks: 5
Thanked 187 Times in 184 Posts
Arbitrator is on a distinguished road
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.
__________________
Please for the love of god stop making IE. You current "browser"s cause me to cry every day. —Phil *
Arbitrator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:23 AM.


Advertisement
Log in to turn off these ads.