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> Link to comment https://forums.phpfreaks.com/topic/216869-confirm-message-box/ 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 Link to comment https://forums.phpfreaks.com/topic/216869-confirm-message-box/#findComment-1126600 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'"; Link to comment https://forums.phpfreaks.com/topic/216869-confirm-message-box/#findComment-1126604 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 . . . Link to comment https://forums.phpfreaks.com/topic/216869-confirm-message-box/#findComment-1126654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.