Page 469 - Beginning PHP 5.3
P. 469
Chapter 14: Manipulating MySQL Data with PHP
Tweaking the view_members.php Script
There ’ s one small change to make to the member list viewer, view_members.php . Open this file and
change the line highlighted in the following code snippet:
< tr < ?php if ( $rowCount % 2 == 0 ) echo ‘ class=”alt”’ ? > >
< td > < a href=”view_member.php?memberId= < ?php echo $member- > getValue
Encoded( “id” ) ? > & amp;start= < ?php echo $start ? > & amp;order= < ?php echo
$order ? > ” > < ?php echo $member- > getValueEncoded( “username” ) ? > < /a > < /td >
< td > < ?php echo $member- > getValueEncoded( “firstName” ) ? > < /td >
< td > < ?php echo $member- > getValueEncoded( “lastName” ) ? > < /td >
< /tr >
The only change here is that the start and order query string parameters are now being passed
through to the view_member.php script. This is so that the administrator can easily return to the same
page in the members list, with the list still sorted by the correct column. You see how this is used in the
view_member.php script in a moment.
Creating the view_member.php Script
The last step to building your member manager is to create a new view_member.php script that allows the
administrator to edit and delete members. The script is based on the view_member.php file that you
created in the previous chapter. The main differences are that the member data is now displayed in a form,
allowing it to be edited, and that the script includes functions for saving edits and deleting a member.
Open your existing view_member.php file and replace its code with the following:
< ?php
require_once( “common.inc.php” );
require_once( “config.php” );
require_once( “Member.class.php” );
require_once( “LogEntry.class.php” );
$memberId = isset( $_REQUEST[“memberId”] ) ? (int)$_REQUEST[“memberId”] : 0;
if ( !$member = Member::getMember( $memberId ) ) {
displayPageHeader( “Error” );
echo “ < div > Member not found. < /div > ”;
displayPageFooter();
exit;
}
if ( isset( $_POST[“action”] ) and $_POST[“action”] == “Save Changes” ) {
saveMember();
431
9/21/09 9:14:13 AM
c14.indd 431
c14.indd 431 9/21/09 9:14:13 AM