1. Buatlah database “guesbook”
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 ;
2. Buat file guestbook.php
Test Sign Guestbook |
View Guestbook |
3. Buatlah file addguestbook.php
$host=”localhost”; // Host name
$username=”"; // Mysql username
$password=”"; // Mysql password
$db_name=”test”; // Database name
$tbl_name=”guestbook”; // Table name
// Connect to server and select database.
mysql_connect(”$host”, “$username”, “$password”)or die(”cannot connect server “);
mysql_select_db(”$db_name”)or die(”cannot select DB”);
$datetime=date(”y-m-d h:i:s”); //date time
$sql=”INSERT INTO $tbl_name(name, email, comment, datetime)VALUES(’$name’, ‘$email’, ‘$comment’, ‘$datetime’)”;
$result=mysql_query($sql);
//check if query successful
if($result){
echo “Successful”;
echo “
”;
echo “View guestbook”; // link to view guestbook page
}
else {
echo “ERROR”;
}
mysql_close();
?>
4. Buat file viewguestbook.php
View Guestbook | Sign Guestbook |
$host=”localhost”; // Host name
$username=”"; // Mysql username
$password=”"; // Mysql password
$db_name=”test”; // Database name
$tbl_name=”guestbook”; // Table name
// Connect to server and select database.
mysql_connect(”$host”, “$username”, “$password”)or die(”cannot connect server “);
mysql_select_db(”$db_name”)or die(”cannot select DB”);
$sql=”SELECT * FROM $tbl_name”;
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
?>
|
}
mysql_close(); //close database
?>
ayo semangat .....Ganbate kudasai!!!!!
!!
Tidak ada komentar:
Posting Komentar