Welcome to the Service Provider Database
"; echo "You have the following choices:"; echo "
"; echo " List service organizations.
"; echo "Add a new organization.

"; echo ""; echo "

"; } /* List the organizations in the contact database plus their phone number. Make the last name clickable for the full record. */ Function Show_Records (){ echo "

Service Providers

"; mysql_connect("luna", "maggot", "fzr400dead"); $result = mysql("services","SELECT * FROM organization"); echo ""; $total_rows = mysql_numrows($result); $counter = 0; echo ""; while($counter < $total_rows) { $uid = mysql_result($result,$counter,uid); echo "
Service Provider
\n"; echo ""; echo mysql_result($result,$counter,org); echo "\n"; echo "\n"; echo mysql_result($result,$counter,uid); echo "\n"; $counter = $counter + 1; } echo "
"; } /* Save updates to database. Call Print_Contact to list new information for updated contact entry. */ Function Commit_Update (){ mysql_connect("luna","maggot","fzr400dead"); $result = mysql("services","UPDATE organization SET org = '$org', phone = '$phone', fax = '$fax', email = '$email', address_1 = '$address1', address_2 = '$address2', URL = '$URL' WHERE uid = 1"); $state = ""; Print_Contact($uid); } /* Save new contact information to database. Call Print_Contact to display new contact entry. */ Function Commit_Contact () { mysql_connect("luna","maggot","fzr400dead"); $result = mysql("services","SELECT now()"); /* Get the Current Datetime */ /* Note that it would be better to use a field of type TIMESTAMP here, since it would automatically assign the current date and time. I haven't done that here since I wanted to demonstrate using functions in MySQL. */ $now = mysql_result($result,0,"now()"); $result = mysql("services","INSERT INTO organization (org,phone, fax, email, address_1, address_2, URL) VALUES ('$org', '$phone', '$fax', '$email', '$address1', '$address2', '$URL')"); $new_uid = mysql_insert_id(); $result = mysql("services","INSERT INTO service (uid, entry_date, service) VALUES (1, '$now' , '$sevice')"); $state = ""; Print_Contact($new_uid); }; /* This function displays the contact information in a form. It is used for both the create and update contact options. */ Function Contact_Form (){ if($state == "Update"){ $state = "Commit_Update"; $result = mysql("services","SELECT * FROM organization WHERE uid=1"); $org = mysql_result($result,0,"org"); $phone = mysql_result($result,0,"phone"); $fax = mysql_result($result,0,"fax"); $email = mysql_result($result,0,"email"); } else { $state = "Commit_Contact"; } echo "

Contact Form

\n"; echo "

\n"; echo " \n"; echo " \n"; echo " Service Provider:

\n"; echo " Email:

\n"; echo " Phone:

\n"; echo " Fax:

\n"; echo " Campus Address:

\n"; echo " URL:

\n"; echo "

\n"; echo "
\n"; } /* Add a comment to the database. Call Print_Contact to display changes. */ Function Add_Service (){ mysql_connect("luna","maggot","fzr400dead"); $result = mysql("services","SELECT now()"); /* Get the Current Datetime */ $now = mysql_result($result,0,"now()"); $result = mysql("services","INSERT INTO service (uid, entry_date, service) VALUES ($uid, '$now', '$newservice')"); Print_Contact($uid); } /* Print address and comments for a contact. Also give option to update or add comments. */ Function Print_Contact (){ mysql_connect("luna","maggot","fzr400dead"); $result = mysql("services","SELECT * FROM contacts WHERE uid=$uid"); $name = mysql_result($result,0,first_name); $name = $name . " " . mysql_result($result,0,last_name); echo "Contact Information For $name"; echo ""; echo ""; echo "

Contact Information For $name

"; echo ""; echo ""; echo ""; mysql_connect("luna","maggot","fzr400dead"); $result = mysql("services","SELECT * FROM organization WHERE uid=1"); echo ""; echo "\n"; echo ""; echo "\n"; $email = mysql_result($result,0,"email"); echo ""; echo "\n"; echo "
Name$name
Phone"; echo mysql_result($result,0,"phone"); echo "
Fax"; echo mysql_result($result,0,"fax"); echo "
Email Address $email"; echo "
"; echo "
"; echo " \n"; echo " \n"; echo "
"; echo "


"; echo "

Services available from this provider

"; echo "
"; $result = mysql("services","SELECT * FROM service WHERE uid=1"); $total_rows = mysql_numrows($result); $counter = 0; echo ""; echo ""; while($counter < $total_rows) { echo ""; $counter = $counter + 1; } echo "
DateComment
"; echo mysql_result($result,$counter,"entry_date"); echo ""; echo mysql_result($result,$counter,"service"); echo "
"; echo "

Add new service below."; echo "

"; echo "


"; echo "

"; echo "

"; echo "

"; echo "

"; echo "

"; echo "
"; echo "
\n"; } /* The main loop. Call functions based on the value of $state, which gets set via a hidden INPUT TYPE. */ switch($state) { case ""; Main_Menu(); break; case "Show Records"; Show_Records(); break; case "Add New Record"; Contact_Form(); break; case "Update"; Contact_Form(); break; case "Commit_Update"; Commit_Update(); break; case "Commit_Contact"; Commit_Contact(); break; case "Add_Service"; Add_Service(); break; case "Print_Contact"; Print_Contact(); } ?>