Hi Guys...

I'm making a form with the ability to delete users. But don't know how to do it...

My form structure..

users.php ---- Lists a user with options like edit user / delete user. (His details are displayed from database on my html page in a table.)

For delete user, I want to (the Delete should only mark as deleted, not physically delete entry ‐ removes auditing ability) from the mysql database.I want to display the confirmination before deleting. Pluse the row which the record is showing on my html page should also be removed...In the database I have a table called users, in the table there is a row/colum called " bIsDeleted ". It's datatype is tinyint and it's defult value is "0". I have build the php syntax for my delete function as follows:

On users.php -- admin clicks on the delete image.

<a href="deleteuser.php?user_Id=<? echo $row["user_Id"] ?>"><img src="images/delete.gif" width="16" height="16" alt="Delete" border="0"/></a>

On deleteuser.php --- my php code...

<?php 

include("_include/ssi/dbconfig.php");

$user_Id = $_GET['user_Id'];

$delete = "UPDATE users SET bIsDeleted = 1 WHERE user_Id='$user_Id' ";
mysql_query($delete);
mysql_close();

echo "Entry deleted";
header("Location: users.php");

?>

In simple words, i want;

1. Delete function -- It should display a confirmation message before deleting.

2. I want the displayed entry on html page to be removed from my html table but not from mysql. It should only be flaged in the databse table.

Thanks...

Recommended Answers

All 2 Replies

Member Avatar for Rhyan

In simple words you have at least 2 options to do no.1, and as I read your code, it seems you've already dealt with no2.

So. Option no.1 - Get a custom javascript to be invoked by pressing the button, wich script will create some sort of pop-up message even prior submitting the data to the deletion page.

Option no 2(wich will work in any kind of browser) even if it's not javascript enabled - create an intermediate page to serve as confirmation. So the confirmation page may show something like this:

Deletion page
============
Are you sure you want to delete current user:
| ID |     NAME      |   E-MAIL   |
|123 | John Doe      |john@doe.com|
<a href="delete.php?userid=123">Confirm</a>
<a href="home.php">Reject</a>

Is this what you ask, or is it something else, as it was not really clear from your question?

(Some awful english coming, hope you can understand it)

The ajax way:

0. Add a status field to users table.
1. In the table add a <td> with checkbox at end of every row. Checkbox id attribute should contain the id of the user (like: usrchkbx456546544).
2. At delete button click, call a javascript function wich contains:
var answer=confirm('Confirm delete user');
Depending the answer return imidietly (cancel), or (ok):
Iterate through all checkboxes inside the table and get user ids from checkbox ids with parseInt where checkbox is checked.
3. Use ajax to to POST selected ids to a php script (deleteuser.php), update the status field at users ids.
$query='UPDATE `users` SET status=0 WHERE id IN(' . $userids . ')';
// $userids is something like this: "534123,8765221,12,9432332,3881"
Print deleted ids coma separeted, or xml formatted.
4. In javascript: process text or xml responsed by php, find all corresponding checkboxes, and remove their parents parent. (checkbox->td->row)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.