954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how can i make php alert pop ups just like in javascript.

I have a php page with two hyperlinks. I one to send email to certain addresses and the other to also send emails to another address and also delete their records from the database.

I don't want a case where the user accidentally clicks on the link takes the wrong action.

i thougth about javascript confirm function. so i tried combining the javascript confirm function and php but i don't seem to get the two working.

i need the results from the confirm function which is either true or false so i can take appropriate action.

Is there an alternative?does php provide similar alert functions? i really need help.

iketunde
Newbie Poster
13 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

In short you can't. But it's very easy to get the same confirmation that you would with a alert box.

1. Pass ID/Email of record along with the delete command, easiest to use a URL

e.g.[PHP] Delete Me[/PHP]

2. On your confirm_delete.php page create two URLs yes or no

e.g.

[PHP]Are you sure you want to delete:

Yes
No[/PHP]

Then on the delete.php page you have some like the following:
[PHP]
if ( $_GET[confirm] == "yes" )
{
mysql_query( "DELETE FROM table WHERE id= '".$_GET[id]."'" );
} else if ( $_GET[confirm] == "no" )
{
header( "location: http://www.yourhomepage.com");
}[/PHP]

Of course this is extremely basic. You would really want to check the variables $_GET[confirm] and $_GET[id] to make sure a hacker wasn't trying to do a sql injection attack on your form. But that's for another discussion. Hope that helps.

msteudel
Newbie Poster
9 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

I'm sure I've seen a tutorial at hotscripts for that.

kiwimedia
Newbie Poster
19 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

Maybe you can use:
<?php echo ';'; ?>
//Khanobly

I have a php page with two hyperlinks. I one to send email to certain addresses and the other to also send emails to another address and also delete their records from the database.

I don't want a case where the user accidentally clicks on the link takes the wrong action.

i thougth about javascript confirm function. so i tried combining the javascript confirm function and php but i don't seem to get the two working.

i need the results from the confirm function which is either true or false so i can take appropriate action.

Is there an alternative?does php provide similar alert functions? i really need help.

khanobly
Newbie Poster
1 post since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

I have a php page with two hyperlinks. I one to send email to certain addresses and the other to also send emails to another address and also delete their records from the database.

I don't want a case where the user accidentally clicks on the link takes the wrong action.

i thougth about javascript confirm function. so i tried combining the javascript confirm function and php but i don't seem to get the two working.

i need the results from the confirm function which is either true or false so i can take appropriate action.

Is there an alternative?does php provide similar alert functions? i really need help.

Javascript is client side (executes on the browser) and PHP is server side (executes on the server).
The confirm box is a function on the browser, so you cannot create a browser confirm box with php unless you use PHP to write out some javascript that will be executed on the browser to display your cofnirm box. (see khanobly's reply)

The only way you can communicate with the php on the server side via javascript is to send the server a new HTTP request (a new page). (exception being xmlHTTPRequest).

In your case, the confirmation box should work just like a normal click on a link (you dont need the javascript to communicate with the php).

eg:

Delete

Lets say the above will invoke the php script task.php and let it know you want to delete something from the database.

We can use javascript to make sure the user doesn't delete by accident.

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

Thank digital-ether for this part: onclick="return (confirm('do you really want to delete the stuff?'))

Tried it with a submit button in a form and it even works here. Perfect. Just what I was looking for.

colweb
Posting Whiz
318 posts since Nov 2007
Reputation Points: 34
Solved Threads: 52
 

I'm sorry! please ignore me... A lot of times I asked questions too fast before figuring it out... Great help! thanks for the codes!

AdventDeo
Light Poster
38 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

Good solution digital-ether >>>>> This is the way to show confirmation message before delete ..... I use this in web development .

mohammed yaghi
Newbie Poster
9 posts since Sep 2010
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You