Link to home
Start Free TrialLog in
Avatar of bleuler
bleuler

asked on

using java script "confirm" with PHP

Hi,

I'm having some problem using Java Script and PHP together. I would like to have a link where I can delete a listed object from a DB. But the User should be asked if he really like to delete the record with a Java Script "confirm" Popup and if he choose no (Abort) the record will not be deleted.
My problem now is the record is deleted anyway doesn't matter if the user click "ok" or "Abort".
Please see my code below:
----------snip------------------------------------------------------------------------------
<?php

//some PHP code here......

?>

<script language="JavaScript">
<!--
if (confirm("Do you really like to delete the System ?")) {
      <?
      //delete the IP's from the Unit
      $query = "delete from unitip where UNIT = '$id'";
      mysql_query($query);
      ?>
      break;
}
else{
      break;
}

// -->
</script>

<?

//some more PHP code......

?>
----------snip------------------------------------------------------------------------------

do you have any idea how to make this work?

thanks & regards
Marc
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
what is happening is the php is getting exicuted before the confirm is even produced.  So what you need to do is have a link that will only go to the page that deletes the record when you click "OK", like what mplungjan said, or you could have one php page that will confirm and then if you click on it will foward you to delete page, if not it will bring you back a page.

-Matt
Any particular reason for the "B" grade?