1.10. Changing Information

People may want to change their names, passwords, and e-mail addresses and it makes sense to allow this in your applications. I've already shown you an example of changing a user record earlier when I first discussed the User class. It's the same process here — simply set the object's properties to new values and call the save() method.

I've saved this code as main.php for the simple fact that login.php redirects the user to main.php after a successful login. In your own implementation, you may want to name it something like editmember.php and have main.php offer some interesting content instead. Either way, the form is shown in Figure 1-6.

Figure 1-6. Figure 1-6
<?php // include shared code include '../lib/common.php'; include '../lib/db.php'; include '../lib/functions.php'; include '../lib/User.php'; // 401 file referenced since user should be logged in to view this page include '401.php'; // generate user information form $user = User::getById($_SESSION['userId']); ob_start(); ?> <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post"> <table> <tr> <td><label>Username</label></td> <td><input type="text" name="username" disabled="disabled" readonly="readonly"value="<?php echo $user->username; ?>"/></td> </tr><tr> <td><label for="email">Email Address</label></td> <td><input type="text" name="email" id="email" value="<?php ...

Get PHP and MySQL®: Create-Modify-Reuse now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.