Jump to content


Photo

PHP and Javascript


  • Please log in to reply
3 replies to this topic

#1 Mateobus

Mateobus
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 25 April 2006 - 04:57 AM

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...
}
}

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 April 2006 - 05:00 AM

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

#3 Mateobus

Mateobus
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 25 April 2006 - 05:53 AM

AJAX, i don't even know what that is... There has to be an easier way.

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 April 2006 - 11:35 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users