hwcasey12 Posted January 29, 2009 Share Posted January 29, 2009 I'm a newbie, so bear with me. I have a table on my site. At the end of each row on the table, I have successfully created a icon image that links to a delete query. It allows a user to click on the image to delete the row. What I would like to do is create a pop warning message (or something else) that warns the user or asks them again if they are sure they want to delete. I wasn't sure what language I would even need to write that in (javascript?). I am looking to learn here, so any direction or links to a good tutorial would be great! Thanks! Link to comment https://forums.phpfreaks.com/topic/143000-solved-how-to-create-pop-up-before-mysql-delete/ Share on other sites More sharing options...
rhodesa Posted January 29, 2009 Share Posted January 29, 2009 yeah...javascript is the way to go (mod...please move this topic) write a JS function: <script type="text/javascript"> function deleteRecord ( id ) { if(confirm("Are you sure you want to delete this?")){ //Put the code you already have to do the delete here } } </script> and add it to your onlcick: <img src="delete.gif" onclick="deleteRecord(123)" /> Link to comment https://forums.phpfreaks.com/topic/143000-solved-how-to-create-pop-up-before-mysql-delete/#findComment-749845 Share on other sites More sharing options...
ialsoagree Posted January 29, 2009 Share Posted January 29, 2009 If you're not sure how to get Javascript to load a new page: <script type="text/javascript"> function deleteRecord ( id ) { if(confirm("Are you sure you want to delete this?")){ document.location.assign('http://yoursite.com/someDeletePHPFile.php?id='+id) } } </script> Link to comment https://forums.phpfreaks.com/topic/143000-solved-how-to-create-pop-up-before-mysql-delete/#findComment-749849 Share on other sites More sharing options...
dennismonsewicz Posted January 29, 2009 Share Posted January 29, 2009 if you wanted it to be smooth and nice looking you could always create a pop up using jQuery or some other js library Link to comment https://forums.phpfreaks.com/topic/143000-solved-how-to-create-pop-up-before-mysql-delete/#findComment-749858 Share on other sites More sharing options...
hwcasey12 Posted January 29, 2009 Author Share Posted January 29, 2009 I do want it to be smooth, but I don't know what you are talking about (dennismonsewicz). But I wish I did! I think I can understand what you both are saying about the code, but I still am not clear as to where to put this code. I have a link (that is an image) in the last column of each row. That link loads this file: <?php $id = $_GET['id']; $con = mysql_connect("localhost", "***", "***") or die('Could not connect to server '); mysql_select_db("equipment", $con) or die('Could not connect to database'); $query="SELECT * FROM inv WHERE id=$id"; $result = mysql_query($query) or die ('Sorry, could not get item detail at this time'); if(mysql_num_rows($result) > 0) { $sql = "DELETE FROM inv WHERE id='$id'"; $result = mysql_query($sql) or die ('Sorry, could not delete item at this time'); echo "Record deleted.<br><br>"; } else { echo "Invalid record<br><br>"; } ?> The link current looks like this: echo "<td><a href='?content=delete&id=$id'><img border=0 src=icons/delete.png width=16 height=16 title='".'Delete'."' alt='".'Delete'."'/></a></td>"; Thanks! Link to comment https://forums.phpfreaks.com/topic/143000-solved-how-to-create-pop-up-before-mysql-delete/#findComment-749873 Share on other sites More sharing options...
rhodesa Posted January 29, 2009 Share Posted January 29, 2009 change the link to: echo '<td><img border="0" src="icons/delete.png" width="16" height="16" title="Delete" alt="Delete" onclick="deleteRecord(\''.$id.'\')" /></td>"; and add this JS function to the top of the page: <script type="text/javascript"> function deleteRecord ( id ) { if(confirm("Are you sure you want to delete this?")){ window.location.href = '?content=delete&id=' + id; } } </script> Link to comment https://forums.phpfreaks.com/topic/143000-solved-how-to-create-pop-up-before-mysql-delete/#findComment-749877 Share on other sites More sharing options...
hwcasey12 Posted January 29, 2009 Author Share Posted January 29, 2009 ;D Sweet! Thanks! It worked like a charm. For future reference...should I have posted this in the javascript section? Link to comment https://forums.phpfreaks.com/topic/143000-solved-how-to-create-pop-up-before-mysql-delete/#findComment-749890 Share on other sites More sharing options...
rhodesa Posted January 29, 2009 Share Posted January 29, 2009 yes...but you weren't 100% sure what language to use, so that is understandable Link to comment https://forums.phpfreaks.com/topic/143000-solved-how-to-create-pop-up-before-mysql-delete/#findComment-749943 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 could off done the same but no pop up with a get[''] within the same page . i think less JavaScript the better but everyone has there own taste. only my opinion Link to comment https://forums.phpfreaks.com/topic/143000-solved-how-to-create-pop-up-before-mysql-delete/#findComment-749952 Share on other sites More sharing options...
jeff5656 Posted January 29, 2009 Share Posted January 29, 2009 How would you do this if instead of an image you had a submit button, where the action goes to delete.php? Link to comment https://forums.phpfreaks.com/topic/143000-solved-how-to-create-pop-up-before-mysql-delete/#findComment-750018 Share on other sites More sharing options...
rhodesa Posted January 29, 2009 Share Posted January 29, 2009 How would you do this if instead of an image you had a submit button, where the action goes to delete.php? instead of hijacking this thread...please start a new one and include a link to this thread Link to comment https://forums.phpfreaks.com/topic/143000-solved-how-to-create-pop-up-before-mysql-delete/#findComment-750022 Share on other sites More sharing options...
ialsoagree Posted January 29, 2009 Share Posted January 29, 2009 could off done the same but no pop up with a get[''] within the same page . i think less JavaScript the better but everyone has there own taste. only my opinion The original poster specifically wanted a pop up message, he was using a normal get link before. Link to comment https://forums.phpfreaks.com/topic/143000-solved-how-to-create-pop-up-before-mysql-delete/#findComment-750127 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.