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.

Setting Up Accounts<br />

669<br />

Listing 29.5<br />

Continued<br />

$query = "update accounts set server = '".$settings[server]."',<br />

port = ".$settings[port].", type = '".$settings[type]."',<br />

remoteuser = '".$settings[remoteuser]."',<br />

remotepassword = '".$settings[remotepassword]."'<br />

where accountid = '".$settings[account]."'<br />

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

} else {<br />

$query = "insert into accounts values ('".$auth_user."',<br />

'".$settings[server]."', '".$settings[port]."',<br />

'".$settings[type]."', '".$settings[remoteuser]."',<br />

'".$settings[remotepassword]."', NULL)";<br />

}<br />

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

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

if ($result) {<br />

return true;<br />

} else {<br />

return false;<br />

}<br />

} else {<br />

echo "Could not store changes.";<br />

return false;<br />

}<br />

}<br />

}<br />

As you can see, two choices within the store_account_settings() function correspond<br />

to inserting a new account or updating an existing account.The function executes<br />

the appropriate query to save the account details.<br />

After storing the account details, you go back to index.php, to the main body stage:<br />

case 'store-settings':<br />

case 'account-setup':<br />

case 'delete-account':<br />

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

break;<br />

As you can see, you then execute the display_account_setup() function as before to<br />

list the user’s account details.The newly added account will now be included.

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

Saved successfully!

Ooh no, something went wrong!