Ok, this is how I would do it assuming you are using ids in your sql database, make another page called edit.php with code like this one:
PHP Code:
<?php
// Get the user id
$id = $_GET['id'];
// Get data from user with the specified id
$info = mysql_query("SELECT * FROM `tbladministrators` WHERE id = '$id'") or die ('Error Getting User Data! <br />' .mysql_error());
$chk = mysql_num_rows($info);
$u = mysql_fetch_array($info);
// If edit not hit
if (!$_POST['edit']) {
// If user id returns no results
if ($chk < 1) {
echo 'The user with the id <b>'.$id.'</b> does not exist!';
}
else {
// Edit Form
?>
<!-- Edit Form -->
<form method="post" action="">
<table width="250">
<tr>
<td>First Name:</td>
<td><input type="text" name="firstname" value="<?php echo $u['firstname'] ?>" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lastname" value="<?php echo $u['lastname'] ?>" /></td>
</tr>
<tr>
<td>Username:</td>
<td><input type="text" name="username" value="<?php echo $u['username'] ?>" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="edit" value="Edit" /></td>
</tr>
</table>
</form>
<!-- /Edit Form -->
<?
}
// If edit was hit
if ($_POST['edit']) {
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
// Update data
$update = mysql_query("UPDATE `tbladministrators` SET firstname = '$firstname', lastname = '$lastname', username = '$username' WHERE id = '$id'") or die ('Error Updating Data! <br />' .mysql_error());
echo 'Update successfull';
}
?>
Now add this line to the end of your page displaying all the users:
PHP Code:
if ($_GET['act'] == 'edit') {
require('edit.php');
}
And finally change the edit link to: <a href="?act=edit&id=<?php echo $qry['id'] ?>">Edit</a>
I also noticed that you have a delete function. You can delete things using: mysql_query("DELTE FROM `tbladministrators` WHERE id = '$id'");
Hope this helps
Bookmarks