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!

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.