Jump to content

[SOLVED] Warning / Confirmation Message on Delete Row


will808

Recommended Posts

Hi,

 

The script below lists all members in a db, and makes a link of the unique ID - clicking the link deletes the row.

 

Since that's a bit trigger happy, I'd like to put a confirmation prompt on the link using PHP or Javascript or something, but I have no idea how to do this (I got suckered into building the website and it's grown into a db admin interface and a steep PHP learning curve from there). Does anyone know how I can create a prompt for the below?

 

<?php include 'dbconnect.php';


//connect to mysql
//then connect as user
     mysql_connect($host,$user,$pass); 

   //select which database you want to edit
   mysql_select_db($db_name); 

//If cmd has not been initialized
if(!isset($cmd)) 
{
   //display all the members
$result = mysql_query("select id, Forename, Surname, CurrentGrade, LicenseExpiry, Phone, Mobile, Email from $table order by id");
   
   //print table headers
    $fields_num = mysql_num_fields($result);

echo "<h5>Table: {$table}</h5>";
echo "<div id=table><table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
    
}

echo "</tr>";


   
   //run the while loop that grabs all the Member Details
   while($r=mysql_fetch_array($result)) 
   { 
   $id=$r["id"];//take out the id
   $Forename=$r["Forename"];//take out the forename
   $Surname=$r["Surname"];//take out the surname
   $CurrentGrade=$r['CurrentGrade'];
   $LicenseExpiry=$r['LicenseExpiry'];
   $Phone=$r['Phone'];
   $Mobile=$r['Mobile'];
   $Email=$r['Email'];
  
     
    
    
 //make the ID & email a link
      echo "<tr><td><a href='delete.php?cmd=delete&id=$id'>$id</a></td>";
      echo "<td>$Forename</td>";
      echo "<td>$Surname</td>";
      echo "<td>$CurrentGrade</td>";
     echo "<td>$LicenseExpiry</td>";
      echo "<td>$Phone</td>";
      echo "<td>$Mobile</td>";
      echo "<td><a href='mailto:$Email'>$Email</a></td>";
      echo "</tr>";
      
    }
    echo "</table></div>";
}
?>


<?php
if($_GET["cmd"]=="delete")
{
$id = $_GET['id'];
    $sql = "DELETE FROM $table WHERE id=$id";
    $result = mysql_query($sql);
    header("Location: display.php"); 
}
?>

 

Thanks for any help  :)

Hi Mate,

 

yep that will work in FF :)

 

Try replacing the single quotes with double:

 

<a href='delete.php?cmd=delete&id=$id' onClick=\"return confirm('Are you sure you want to delete this row?')\">Delete</a>

 

Graham

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.