Jump to content

PHP and Javascript


Mateobus

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...
}
}
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.