Joe's Address Book

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:
"; $all_result = pg_query ( "select * from contacts where email='$email'" ); $result_array = pg_fetch_array ( $all_result ); foreach ( $result_array as $key => $value ) { $$key=$value; } } else { echo "

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 "

"; if ( $_POST['submit'] != "Submit" ) { echo"
email:
Password:"; echo""; if ( $top ) echo "  (leave blank for none)"; echo "
"; echo "First name:
Last name:
Get mailed stories as I write them.
Get mailed journals as I write them.
 

This address/phone stuff is all optional, of course...
but no postcards from Chengdu if you don't  :-)

Phone  e.g., 510.456.7890
Address:
More Address:
City:
State:   Zip:  "; echo "
 
The journals I expect will be out maybe every week or so and won't
be terribly polished.  Stories I'll try to make more finished and interesting,
maybe once a month. "; } ?>