yash87 Posted October 26, 2010 Share Posted October 26, 2010 Can anyone help me with this delete confirm box. I have tried but somehow its not working. Can anyone help me with this? Thankz. html codes : echo "<td><a href=delete.php?id=" . $rows['id'] ." onclick=\"return confirm(Are you sure?);\">Delete</a></td>"; delete.php : <?php include "config.php"; ?> <?php $id=$_GET['id']; ?> <script type="text/javascript"> <!-- function confirmation() { var answer = confirm('Are you sure you want to delete?') if (answer){ $sql="DELETE FROM document WHERE id='$id'"; } else{ alert("Cancelled the delete!") } } </script> Quote Link to comment Share on other sites More sharing options...
rwwd Posted October 26, 2010 Share Posted October 26, 2010 Far be it from me to criticise, but I dont think as this is possible the way your structuring it, you cant use JS to manipulate php, but you CAN use php to manipluate JS. JS is client side; php is server side; php renders text client side. Rw Quote Link to comment Share on other sites More sharing options...
vichu.1985 Posted October 26, 2010 Share Posted October 26, 2010 Dude, I guess u need to change your logic as follows: In first file, separate JS code - <script type="text/javascript"> function call_confirm(){ var answer = window.confirm ("Are you sure you want to delete?"); if (answer) return true; else return false; } </script> <?php echo "<td><a href=delete.php?id=" . $rows['id'] ." onclick=\"return call_confirm()\">Delete</a></td>"; ?> In your delete.php, directly write query. $id=$_GET['id']; $sql="DELETE FROM document WHERE id='$id'"; Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 26, 2010 Share Posted October 26, 2010 You need to make sure you sanitize the data coming from the GET var too . . . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.