13.09.2016 Views

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

704 Chapter 30 Building a Mailing List Manager<br />

The store_account() function, shown in Listing 30.4, writes the account details to the<br />

database.<br />

Listing 30.4 store_account()Function from mlm_fns.php—This Function Adds a<br />

New User to the Database or Stores Modified Details About an Existing User<br />

// add a new subscriber to the database, or let a user modify their data<br />

function store_account($normal_user, $admin_user, $details) {<br />

if(!filled_out($details)) {<br />

echo "All fields must be filled in. Try again.";<br />

return false;<br />

} else {<br />

if(subscriber_exists($details['email'])) {<br />

//check logged in as the user they are trying to change<br />

if(get_email()==$details['email']) {<br />

$query = "update subscribers set<br />

realname = '".$details[realname]."',<br />

mimetype = '".$details[mimetype]."'<br />

where email = '".$details[email]."'";<br />

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

if ($conn->query($query)) {<br />

return true;<br />

} else {<br />

return false;<br />

}<br />

} else {<br />

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

return false;<br />

}<br />

} else {<br />

echo "Sorry, that email address is already registered here.<br />

You will need to log in with that address to<br />

change its settings.";<br />

return false;<br />

}<br />

} else {<br />

// new account<br />

$query = "insert into subscribers<br />

values ('".$details[email]."',<br />

'".$details[realname]."',<br />

'".$details[mimetype]."',<br />

sha1('".$details[new_password]."'),<br />

0)";<br />

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

if ($conn->query($query)) {

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

Saved successfully!

Ooh no, something went wrong!