13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

670 Chapter 29 Building a <strong>Web</strong>-Based Email Service<br />

Modifying an Existing Account<br />

The process for modifying an existing account is similar.The user can change the<br />

account details <strong>and</strong> click the Save Changes button. Again, this activity triggers the<br />

store-settings action, but this time it updates the account details instead of inserting<br />

them.<br />

Deleting an Account<br />

To delete an account, the user can click the Delete Account button shown under each<br />

account listing. Doing so activates the delete-account action.<br />

In the preprocessing section of the index.php script, you execute the following code:<br />

case 'delete-account':<br />

delete_account($_SESSION['auth_user'], $account);<br />

break;<br />

This code calls the delete_account() function.The code for this function is shown in<br />

Listing 29.6. Account deletion needs to be h<strong>and</strong>led before the header because a choice<br />

of which account to use is located inside the header.The account list needs to be updated<br />

before it can be correctly drawn.<br />

Listing 29.6 delete_account() Function from mail_fns.php—Function to Delete<br />

a Single Account’s Details<br />

function delete_account($auth_user, $accountid) {<br />

//delete one of this user's accounts from the DB<br />

$query = "delete from accounts where accountid = '".$accountid."'<br />

<strong>and</strong> username = '".$auth_user."'";<br />

if($conn=db_connect()) {<br />

$result = $conn->query($query);<br />

}<br />

return $result;<br />

}<br />

After execution returns to index.php, the body stage runs the following code:<br />

case 'store-settings':<br />

case 'account-setup':<br />

case 'delete-account':<br />

display_account_setup($_SESSION['auth_user']);<br />

break;<br />

Notice that this is the same code you ran before; it just displays the list of the user’s<br />

accounts.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!