Database and webpage design at

Project Report

Chia-Yao Chien

June 4, 2006

1.Abstract

My first attempt to this project is that I was hoping to get some real working experience before graduate. Therefore, I spent several weeks trying to contact several different organizations and finally got in touch with HBN. The main idea is that they ask me to create several pages to help them organize with the member information and further increment functions to withtheir mysql database.

2.Introduction

The website is built on a hosting company called Start Logic. Therefore, they only support its client building the database using phpmyAdmin, and it provides us to connect to the database using PHP. I created severalPHP files to fulfill my client’s needs. One register form, one login form, one administrator page, two links for ID and password reminder, email and newsletter send out form, guestbook, a chat room and another page to publish daily news on the website.

3.Technological Background

All the files are finished on PHP. PHP is a simple and friendly language. It can be used within html code, and it is also very easy to connect to mysql database.

3.1Login Form

Login formis basically the simplest. It has nothing much to do with PHP coding. I basically created it in html form. I add setcookie() functionwithinPHP code for security purpose. And also, if the administrator disables the user in the admin page, member won’t be able to login through the page.

Fig.1 Login form

3.2Register Form

I use if-else loop to block out the errors when the fields are not filled properly. If there is no error shows, it connects to the mysql and insert the values into the database.

Fig. 2 Register Form

Fig. 3 Register Error messages

3.3AdministratorPage

Administratorpage is where the database is shown for the officers. I created the page with decent/ascent order of different fields, and also the officers are able to disable and enable users using the buttons below the form. Other than that, they can send out emails for selected members and also newsletters using the textbox in the page.

For all the pages after login, I set the code to exam cookie for security reason.

<?php

if($_COOKIE['name'] == null){

die;}

?>

And if the administrator decide to disable the member, the page links to the database and set the secure code into 0 instead of 1.

Fig. 4 Administration Form

3.4Daily News publish page

Fig. 5 Blog Entry

Fig. 6 Blog re-Entry

The idea comes from creating a bulletin board to public the daily news on the website. The officer at HBN told me they need a bulletin board as a blog format on the website. So I create a link from the administrator page to enter, or if necessary, re-enter the content for the current day.

The first blog-entry page as Fig. 5 links to the re-entry page as Fig. 6 after the submit button is clicked.

The content of the blog is created in the database. For the re-entry page, I use if-else loop to exam the content of the database for the current. If the content of the blog for the current day is created already, then the administrator has to type in the renew content at the re-entry textbox if they decide to change the content of the current day bulletin board.

$query = "Select id, date from blog";

$result = mysql_query($query);

while($row = mysql_fetch_array($result)){

$sqlDate = substr($row[1],0,8);

if($date == $sqlDate){

$id[$count] = $row[0];

$count++;

//if the current date == any of the date stored in the database, error message might generate.

}

}

if (isset($_POST['re_enter']) & !$_POST['logtext2'] == null ) {

//if the re-entry button is clicked and the content of the re-entry textbook is not null, delete the field and re-insert the new content

for($i=0; $i<$count; $i++){

$query4[$i] = "DELETE from blog where ID = $id[$i]";}

$query2 = "INSERT INTO blog (blogtext , date )VALUES('$tr_text2'now() )";}

if (isset($_POST['logtext'] ) & $count == 0) {

//no content is entered to the current day yet. Insert the content from the original entry textbox into the database. }

elseif($count == 1 & !isset($_POST['re_enter'])){

//content is already written into the database and the re-entry submit button is not clicked, print out “weblog for today is already written.” }

After the bulletin content is entered, the bulletin board is able to show as a daily mode and a calendar mode.

In the bulletin daily mode, the content is shown as the current date in default, and I used the flip-bar of “<-- previous” and “-->next” to generate the dates on the url and further pull out the content of the specific date from the database.

//calculate the flip bar

$prevdate = $date - 1;

$nextdate = $date + 1;

if ($date == $initial_entry_date) {

$flipbar = "\n<P CLASS=\"next\"<A HREF=\"$PHP_SELF?date=$nextdate\">Next --</A</P>\n";

} elseif ($date == $today) {

$flipbar = "\n<P CLASS=\"previous\"<A HREF=\"$PHP_SELF?date=$prevdate\"<-- Previous</A</P>\n";

} else {

$flipbar = "\n<TABLE BORDER=0<TR<TD WIDTH=\"50%\" ALIGN=\"left\"<SPAN CLASS=\"previous\">

<A HREF=\"$PHP_SELF?date=$prevdate\"<-- Previous</A</SPAN</TD>

<TD WIDTH=\"50%\" ALIGN=\"right\"<SPAN CLASS=\"next\">

<A HREF=\"$PHP_SELF?date=$nextdate\">Next -->

</A</SPAN</TD</TR</TABLE>\n";

}

//pull out the content of the specific date from the website.

$date = $_GET[‘date’];

$query = "select * from blog";

$result = mysql_query($query);

while($row = mysql_fetch_array($result) ){

$sqlDate = substr($row[2],0,8);

if($sqlDate == $date ){

echo stripcslashes($row[1]) ."<br>";

$count++;}

}

Fig. 6 Blog normal mode

In the bulletin calendar mode, I spent most of time calculating and print out the table as a calendar. Php has several very useful functions as date() and mktime() to specifically calculate the date, month, and year as we want. Then I use several for-loop to clear out the blank fields of the first and last row of the table. At last I assign the link of the dates that has contents of the bulletin board to the dates on the calendar.

//calculate the first row

$firstday = mktime(0, 0, 0, $month, 1, $year);

$weekdayF = date("w", $firstday);

for($k=0;$k<$weekdayF;$k++){

$cal[$k][0] = "";//before the first day, the fields on the calendar table are blank}

for($l=$weekdayF;$l<=6; $l++){

//$Febdate3[$a] = mktime(0, 0, 0, $month, $a, $year);

$cal[$l][0] = $dateArray[$a];

$a++;}

//calculate if there is the fifth row

$lastDay = date("d", mktime(0, 0, 0, $month, $totalDays, $year));

if(isset($cal[6][4])){

if($lastDay > $cal[6][4]){

$fifthRow = 0;

for($g = $cal[6][4]+1; $g<=$lastDay; $g++){

$weekday2[$fifthRow] = date("w", mktime(0, 0, 0, $month, $g, $year));

if($weekday2[$fifthRow] == 0){

$w=0;

$cal[$w][5] = $dateArray[$g];}

//Sunday

elseif($weekday2[$fifthRow] == 1){

$w=1;

$cal[$w][5] = $dateArray[$g];}

//Monday

$fifthRow++;

}//end of for

for($l=date("w", mktime(0, 0, 0, $month, $lastDay, $year))+1;$l<=6; $l++){

$cal[$l][5] = "";}

}

}//end of if(isset($cal[6][4]))

else{

//calculate the blank field of the fourth row

$weekdayL = date("w", mktime(0, 0, 0, $month, $lastDay, $year));

for($g=$weekdayL+1; $g<=6; $g++){

$cal[$g][4] = "";}

}//end of else

//calculate the link of the bulletin to print on the calendar

$query = "select * from blog";

$result = mysql_query($query);

while($row = mysql_fetch_array($result) ){

$sqlmonth = substr($row[2],4,2);

$sqlday = substr($row[2],6,2);

$sqlactualDate = substr($row[2],0,8);

if($sqlmonth == $month ){

$actualDates[$r] = $sqlactualDate;

$dates[$r] = $sqlday;

$r++;}

}

//put in the ones with the blog content

for($w = 1; $w <=$totalDays; $w++){

for($g=0;$g<$r;$g++){

if($w == $dates[$g]){

$dateArray[$w] = "<a href=\" } }

}

//put in the rest of the days into the array

for($w = 1; $w <=$totalDays; $w++){

if(!isSet($dateArray[$w])){

$dateArray[$w] = $w;}

}

Fig. 7 Blog calendar mode

P.S The format of the bulletin is by referenceof

3.5Email, newsletter send out textbox

If the PHP platform is set to a personal user, they need to set values at php.ini for them to initiate the smtp function to send out the emails using PHP. However, I don’t have access to the start logic server to put in the php.ini file, so all I did was simply add several headers and mailto functions within my PHP code to send out the email.

$result4 = mysql_query("SELECT email, Salutation, Lname FROM member_user WHERE User_Id = '$u[$i]' ") or die(mysql_error());

//if the checkbox is selected, and the value of the checkbox $u[] is equal to User_ID

//content of the mail

$address = $email;

$subject = "Dear HBN Customer";

$message = "

<html>

<IMG SRC=\"

Dear $Salutation $Lname:

$content//content from the textbox

</html>

";

$from = "";

$headers .= 'Content-type: text/html; ' . "\r\n";

$mailsend = mail($address, $subject, $message, "From: $from",

3.6ID and password reminder

If the member forgot their id or password, they need to fill out information that matches with the database, and their email address, and we will send out the information and link to recreate the password to their email box.

Fig. 8 ID reminder

Fig. 9 Password reminder

3.7Guestbook

I created guestbook based on a txt file. After the member login into the website, they are able to sign up the guestbook from the textbox.

$file = fopen($guestbook, "a");//for write from the end of the file

if (!$file) {

echo "Can't write to guestbook file";

die;}

$date = date('F j, Y, g:i a');

$comment = $_POST['comment'];

$mName = $_COOKIE['name'];

fwrite($file,"$date\t$mName\t$comment\n");

fclose($file);}

$file = @fopen($guestbook, 'r');//file read

$rows = -1;

if ($file) {

while (!feof($file)) {

$line2 = fgets($file);

$rows ++;}

}

fclose($file);

$file = @fopen($guestbook, 'r');

if ($file) {

for ($i=0; $i < $rows; $i++){

$line = fgets($file);

list ($date, $mName, $comment) = split("\t", $line, 4);

echo "<tr<td>$date</td<td>$mName</td>";

echo "<td>$comment</td</tr>\n";}

fclose($file);

}

Fig. 9 Password reminder

3.8Chat room

Chat room was incremented by another guy who built part of the website. He incremented the char room from a website called EveryWhereChat.com. There is a “chat code generator” on their website, and as long as we input the format of the chat room, it will generate the code as an asp file for us. For some reason, the chat room didn’t work when it was first generated, so I incremented the code again and add the cookie header for security.

3.9Logout

I link the logout page to a separate php file which clears out the cookie and then redirect it back to home page.

<?php

setcookie("name",””, time()-7200); //clear out cookie value after two hours

header('location:../home.html'); //redirect to homepage.

?>

4.System Architecture

I find the project the most confusing part is the organization does not want me to increment too many functions for their website because they only wanted to keep the website mainly for offering information to their client. However, Itried my best to think of the functions for the officers to use the web pagesI created for them in the most efficient way. Basically the links and the logic of the pages are pretty simply. I am looking forward to increment more functions for the member use login, such as chat room, guess book, and web log.

5.Conclusion

It sure is an interesting project to build a website to fulfill the needs of a client. However, I do feel kind of disappointed since my client doesn’t know very specifically about what they need to have on their website, and a lot of time they are not that interested in incrementing new functions as I suggested. But it is a very good experience to learn to communicate with a client and build a website, and I am glad I learned a lot about php and wepage design through this project.

6. References

[1] PHP Bible 2nd Edition. Wiley.September 11, 2002

[2]

[3] Teach Yourself PHP in 24 Hours. SAMS. September 30, 2005

[4]