Code:
if(!is_numeric($id = (@$_GET['id'] or $_POST['id'])))
// throw an error and die
$users_table = 'users';
$acceptable_rows = array('username', 'email');
if(isset($_POST['username'])) {
foreach($acceptable_rows as $row => $value)
mysql_query(sprintf('update %s where id=%d set \'%s\'=\'%s\'', $users_table, $id, $row, $value));
// output a success message and die
}
$user = mysql_fetch_array(mysql_query(sprintf('select * from %s where id=%d', $users_table, $id)));
?>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post">
<table>
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email Address</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<?php echo($user['id']); ?>
<input type="hidden" name="id" value="<?php echo($user['id']); ?>">
</td>
<td>
<input type="text" name="username" value="<?php echo($user['username']); ?>">
</td>
<td>
<input type="text" name="email" value="<?php echo($user['email']); ?>">
</td>
<td>
<input type="submit" value="OK">
</td>
</tr>
</tbody>
</table>
</form>
Bookmarks