Jump to content

[SOLVED] How to create pop up before mysql delete.


hwcasey12

Recommended Posts

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!

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)" />

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>

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!

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>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.