will808 Posted January 4, 2009 Share Posted January 4, 2009 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 Link to comment https://forums.phpfreaks.com/topic/139415-solved-warning-confirmation-message-on-delete-row/ Share on other sites More sharing options...
graham23s Posted January 4, 2009 Share Posted January 4, 2009 Hey matey echo "<tr><td><a href='delete.php?cmd=delete&id=$id' onClick='return confirm('Are you sure you want to delete row?')'>$id</a></td>"; try this Graham Link to comment https://forums.phpfreaks.com/topic/139415-solved-warning-confirmation-message-on-delete-row/#findComment-729274 Share on other sites More sharing options...
will808 Posted January 4, 2009 Author Share Posted January 4, 2009 Hi Graham, Thanks for the reply - I've added as you suggest, but I'm not getting the confirm - it still deletes the row OK though. I've only tried this in Firefox - but guess it ought to work OK in FF? Link to comment https://forums.phpfreaks.com/topic/139415-solved-warning-confirmation-message-on-delete-row/#findComment-729276 Share on other sites More sharing options...
graham23s Posted January 4, 2009 Share Posted January 4, 2009 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 Link to comment https://forums.phpfreaks.com/topic/139415-solved-warning-confirmation-message-on-delete-row/#findComment-729277 Share on other sites More sharing options...
will808 Posted January 4, 2009 Author Share Posted January 4, 2009 Perfect, that's done it - many thanks Graham! Link to comment https://forums.phpfreaks.com/topic/139415-solved-warning-confirmation-message-on-delete-row/#findComment-729278 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.