Membuat Buku Tamu Sederhana dari PHP
Rocky Christmas Tarigan
Buat Databasenya berikut rinciannya
CREATE TABLE `guestbook` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
`comment` longtext NOT NULL,
`datetime` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
- Membuat file guestbook.php
Tampilan dari file guestbook.php
01 | <table width= "400" border= "0" align= "center" cellpadding= "3" cellspacing= "0" > |
03 | <td><strong>Test Sign Guestbook </strong></td> |
06 | <table width= "400" border= "0" align= "center" cellpadding= "0" cellspacing= "1" bgcolor= "#CCCCCC" > |
08 | <form id= "form1" name= "form1" method= "post" action= "addguestbook.php" > |
10 | <table width= "400" border= "0" cellpadding= "3" cellspacing= "1" bgcolor= "#FFFFFF" > |
12 | <td width= "117" >Name</td> |
14 | <td width= "357" ><input name= "name" type= "text" id= "name" size= "40" /></td> |
19 | <td><input name= "email" type= "text" id= "email" size= "40" /></td> |
22 | <td valign= "top" >Comment</td> |
23 | <td valign= "top" >:</td> |
24 | <td><textarea name= "comment" cols= "40" rows= "3" id= "comment" ></textarea></td> |
29 | <td><input type= "submit" name= "Submit" value= "Submit" /> <input type= "reset" name= "Submit2" value= "Reset" /></td> |
36 | <table width= "400" border= "0" align= "center" cellpadding= "3" cellspacing= "0" > |
38 | <td><strong><a href= "viewguestbook.php" >View Guestbook</a> </strong></td> |
- Membuat file addguestbook.php
09 | mysql_connect( "$host" , "$username" , "$password" ) or die ( "cannot connect server " ); |
10 | mysql_select_db( "$db_name" ) or die ( "cannot select DB" ); |
12 | $datetime = date ( "y-m-d h:i:s" ); |
14 | $sql = "INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')" ; |
15 | $result =mysql_query( $sql ); |
21 | echo "<a href='viewguestbook.php'>View guestbook</a>" ; |
- Membuat file viewguestbook.php
01 | <table width= "400" border= "0" align= "center" cellpadding= "3" cellspacing= "0" > |
03 | <td><strong>View Guestbook | <a href= "guestbook.php" >Sign Guestbook</a> </strong></td> |
17 | mysql_connect( "$host" , "$username" , "$password" ) or die ( "cannot connect server " ); |
18 | mysql_select_db( "$db_name" ) or die ( "cannot select DB" ); |
20 | $sql = "SELECT * FROM $tbl_name" ; |
21 | $result =mysql_query( $sql ); |
23 | while ( $rows =mysql_fetch_array( $result )){ |
25 | <table width= "400" border= "0" align= "center" cellpadding= "0" cellspacing= "1" bgcolor= "#CCCCCC" > |
27 | <td><table width= "400" border= "0" cellpadding= "3" cellspacing= "1" bgcolor= "#FFFFFF" > |
31 | <td><? echo $rows [ 'id' ]; ?></td> |
34 | <td width= "117" >Name</td> |
36 | <td width= "357" ><? echo $rows [ 'name' ]; ?></td> |
41 | <td><? echo $rows [ 'email' ]; ?></td> |
44 | <td valign= "top" >Comment</td> |
45 | <td valign= "top" >:</td> |
46 | <td><? echo $rows [ 'comment' ]; ?></td> |
49 | <td valign= "top" > Date /Time </td> |
50 | <td valign= "top" >:</td> |
51 | <td><? echo $rows [ 'datetime' ]; ?></td> |
0 comments:
Post a Comment
KOMENTAR