Jump to content

Archived

This topic is now archived and is closed to further replies.

Mateobus

PHP and Javascript

Recommended Posts

OK, I am trying to use php and javascript together and I have made more progress than I thought originally. The idea is that I want to have a delete option for some data in my mySQL database. IF the user clicks the delete link, it passes the ID to the confirmation(id) function. I have this working. Now I want to make the query that uses that ID, not as easy. Here is the code I have, anyone got the rest...

function confirmation(id) {
var answer = confirm("Delete data: "+id+"?")
if (answer){
<?php
$sql = "DELETE FROM table WHERE id='";
?>
//I want to say ID here...
}
}

Share this post


Link to post
Share on other sites
Remember, PHP runs on the server and Javascript runs on the client. By the time the Javascript gets to put out the confirm message, PHP is long gone. What you may have to do is do some AJAX scripting to invoke a small PHP script sending it the ID to delete.

Ken

Share this post


Link to post
Share on other sites
AJAX is the fancy new name given to Asynchronous Javascript. There is a sister site to this one named [a href=\"http://www.ajaxfreaks.com\" target=\"_blank\"]Ajaxfreaks[/a] where you can find out some more information.

Actually AJAX isn't very hard to learn. And it makes possible the interaction that you want to do. Before people started exploring it, there was no way for Javascript to dynamically get results from a PHP script.

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.