Using javascript confrim to do php

+1 Gary Miller · December 9, 2014

function delete($post_id, $num) {
$conbox = '<script>var conbox = window.confirm("Post '.$num.' is going to be deleted");</script>';
echo $conbox;
echo '<script>(conbox) { </script>';
Global $mysql;
$mysql->query("DELETE FROM `post` WHERE `post_id` = $post_id");
echo '<script> } else {alert("okay"); }</script>';


this function dose delete the post but it does even if the user clicks cancel. if the user clicks cancel obviously i don't want it to delete the post so i added the alert function for testing. Ive tried many combos of the code and can't figure it out. 

Post a Reply


Oldest  Newest  Rating
0 Gary Miller · December 13, 2014
Yes but thank you I will look into ajax
+2 Samuel Oloruntoba · December 9, 2014
The truth behind the code you wrote is that it will delete the post whether the users presses any of the buttons or not, if you want javascript to trigger php code, use ajax
  • 1



A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.