Specifications
function will display the form that we can see in Figure 27.4. You can see that we use it in two
different ways here: We use it with no parameters to display an empty form, and we use it with
a full set of parameters to display an existing record. This function is in the output_fns.php
library; it simply outputs HTML so we will not go through it here.
The function that retrieves any existing accounts is get_accounts(), from the mail_fns.php
library. This function is shown in Listing 27.4.
LISTING 27.4 get_accounts() Function from mail_fns.php—Function to Retrieve All the
Account Details for a Particular User
function get_accounts($auth_user)
{
$list = array();
if(db_connect())
{
$query = “select * from accounts where username = ‘$auth_user’”;
$result = mysql_query($query);
if($result)
{
while($settings = mysql_fetch_array($result))
array_push( $list, $settings);
}
else
return false;
}
return $list;
}
As you can see, this function connects to the database, retrieves all the accounts for a particular
user, and returns them as an array.
Creating a New Account
If a user fills out the account form and clicks the Save Changes button, the store-settings
action will be activated. Let’s look at the event handling code for this from index.php. In the
preprocessing stage, we execute the following code:
case ‘store-settings’ :
{
store_account_settings($auth_user, $HTTP_POST_VARS);
break;
}
The store_account_settings() function writes the new account details into the database.
The code for this function is shown in Listing 27.5.
Building Practical PHP and MySQL Projects
P
ART V
634
33 7842 CH27 3/6/01 3:41 PM Page 634










