$title = "Joe's Address Book"; include ( "../header.php" ); ?>
Joe's Address Book |
if ( $_POST['submit'] != "Submit" ) {
echo "If you're new, just enter your information and hit submit. To change existing info, enter your email address and password, and hitting \"submit\" will bring up what's on file in the database so you can edit it."; } $story_checked="checked"; $top=false; if ( $_POST['submit'] == "Submit" ) { foreach ( $_POST as $key=>$value ) { $$key=$value; } $email_pref="none"; if ( $story_list=="on" && $journal_list=="on" ) { $email_pref="both"; } elseif ( $story_list=="on" ) { $email_pref="story"; } elseif ( $journal_list=="on" ) { $email_pref="journal"; } $connection=pg_pconnect ( $connection_string ); if ( $email != "" ) { if ( $id != "" ) { $result = pg_query ( "select email, password from contacts where id='$id'" ); } else { $result = pg_query ( "select email, password from contacts where email='$email'" ); } if ( pg_numrows ( $result ) == 0 && $first == "" && $id=="" ) { echo "Can't find you in the database; fill in your information to make a new entry, or else check your email address and try again."; } elseif ( pg_numrows ( $result ) == 0 && $first != "" && $id=="" ) { // new record $insert_sql = "insert into contacts values ( nextval('contacts_id_seq'), '$first', '$last', '$phone','$email', '$address_1', '$address_2', '$city', '$state', '$postal', '$email_pref', '$password' )"; $insert_result = pg_query ( $insert_sql ); if ( ! $insert_result ) { echo "Uh, oh, problems. Can you back up and try that again? Thanks..."; } else { echo "$email added to Joe's contact mailing list."; } } elseif ( pg_result ( $result, 0, 1 ) == "$password" && $first != "" && id != "" ) { // update $update_sql = "update contacts set first='$first', last='$last', phone='$phone', email='$email', address_1='$address_1', address_2='$address_2', city='$city', state='$state', postal='$postal', email_pref='$email_pref', password='$password' WHERE id='$id'"; $update_result = pg_query ( $update_sql ); if ( ! $update_result ) { echo " Uh, oh, looks like trouble. Can you back up and try that again? Thanks...";
} else { echo "Information for $email updated."; }
} elseif ( pg_result ( $result, 0, 1 ) == "$password" ) {
echo "Your current info on file, you can edit and re-submit to change: Password did not match -- sorry, but you can't change your password. "; } } } else { $top=true; } $email_pref = rtrim ($email_pref); switch ( $email_pref ) { case "both": $journal_checked="checked"; $story_checked="checked"; break; case "story": $journal_checked=""; $story_checked="checked"; break; case "journal": $journal_checked="checked"; $story_checked=""; break; default: $journal_checked=""; $story_checked=""; } if ( $top ) $story_checked="checked"; echo " |