tagert123 Posted August 29, 2008 Share Posted August 29, 2008 ok heres the thing. i would need to add a sort of a are you sure question when someone clicks on the delete record command ona a form for editing the database. so heres the code i got for deleting a record: if ($submit) { // here if no ID then adding else we're editing if ($id) { $sql = "UPDATE profile SET name='$name',name2='$name2',backgroundimage='$backgroundimage',listassignement='$listassignement',listassignement2='$listassignement2',listposition='$listposition',listposition2='$listposition2',rank_image='$rank_image', medal_image='$medal_image', rank='$rank', species='$species', birthplace='$birthplace', current_posting='$current_posting', qualification='$qualification', age='$age', sex='$sex', dob='$dob', appearance='$appearance',history='$history', background='$background', service_record='$service_record', commendations='$commendations', reprimands='$reprimands', med_record='$med_record', interests='$interests', added_notes='$added_notes', picture='$picture', type='$type' WHERE id=$id"; } else { $sql = "INSERT INTO profile (name,name2,listassignement,backgroundimage,listassignement2,listposition,listposition2,rank_image,medal_image,rank,species,birthplace,current_posting,qualification,age,sex,dob,appearance,history,background,service_record,commendations,reprimands,med_record,interests,added_notes,picture,type) VALUES ('$name','$name2','$backgroundimage','$listassignement','$listassignement2','$listposition','$listposition2','$rank_image','$medal_image','$rank','$species','$birthplace','$current_posting','$qualification','$age','$sex','$dob','$appearance','$history','$background','$service_record','$commendations','$reprimands','$med_record','$interests','$added_notes','$picture','$type')"; } // run SQL against the DB $result = mysql_query($sql) or die(mysql_error()); echo "Record updated/edited!<p>"; } elseif ($delete) { // delete a record $sql = "DELETE FROM profile WHERE id=$id"; $result = mysql_query($sql); echo "$sql Record deleted!<p>"; } else { // this part happens if we don't press submit if (!$id) { // print the list if there is not editing $result = mysql_query("SELECT * FROM profile ORDER BY name",$db); while ($myrow = mysql_fetch_array($result)) { printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["id"], $myrow["name"], $myrow["rank"]); printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/121892-delete-record-confirmation/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.