Langsung ke konten utama

Bukutamu sederhana dengan php

Hai! Nah kali ini saya akan menshare ilmu tentang cara membuat bukutamu sederhana dengan php.

Mungkin ini trik usang karena sudah banyak bertebaran cms untuk membuat bukutamu, tapi tidak ada salahnya belajar membuat bukutamu dari awal karena kode yang dihasilkan lebih fresh daripada download segala macem kode.



Ok, let's code!

Untuk permulaan kita akan membuat database terlebih dahulu. Berikut saya jelaskan:
1. buka phpmyadmin dan buat databasenya dengan nama bukutamu
2. setelah jadi buat tabel dengan nama tampil dan rincian sbb:
id | INT(4) | NOT NULL | auto_increment | Primary Key
nama | VARCHAR(30) | NOT NULL
email | VARCHAR(25) | NOT NULL
pesan | TEXT | NOT NULL
tanggal | DATE | NOT NULL
ip | VARCHAR(30) | NOT NULL

3. Setelah siap kita buat halaman bukutamunya, ketik kode berikut dan simpan dengan nama koneksidb.php

<?php
/************************************
* File koneksi ke database
* Silakan ganti variabelnya dengan
* host, username, password, dan database
* anda
*************************************/
$host = "localhost";
$username = "root";
$password = "";
$database = "bukutamu";

$konek = mysql_connect($host, $username, $password) or die("Gagal koneksi");
$pilih = mysql_select_db($database, $konek) or die("No database in here");
?>

4. Ketik kode berikut dan simpan dengan nama bukutamu.php

<html>
    <head>
        <title>Bukutamu</title>
    </head>
    <body bgcolor="#FFFFFF">
        <table width="100%" border="0" align="left">
            <form action="bukuProses.php" method="post">
                <tr><td>Nama</td><td><input type="text" name="nama"></td></tr>
                <tr><td>Email</td><td><input type="text" name="email"></td></tr>
                <tr><td>Pesan</td><td><textarea name="pesan" cols="30" rows="10"></textarea></td></tr>
                <tr><td></td><td><input type="submit" name="kirim" value="kirim"></td></tr>
                <input type="hidden" name="ip" value="<?php echo $_SERVER ['REMOTE_ADDR']; ?>">
            </form>
        </table>
    </body>
</html>

5. Ketik (lagi-lagi) kode berikut dan simpan dengan nama bukuProses.php

<?php
include "koneksi.php";
$nama = htmlspecialchars($_POST ['nama']);
$email = htmlspecialchars($_POST ['email']);
$pesan = htmlspecialchars($_POST ['pesan']);
$ip = $_POST ['ip'];
$tanggal = date('Y-m-d');

$kueri = "insert into bukutamu(nama, email, pesan, tanggal, ip) values('$nama', '$email', '$pesan', '$tanggal', '$ip');";

$masuk_kueri = mysql_query($kueri);
if ($masuk_kueri) {
    echo "Data berhasil diinput";
}
else {
    echo "Data gagal dimasukkan";
}
?>
6. Gak bosen kan? Ketik kode berikut dengan nama bukuTampil.php

<html>
    <head>
        <title>Semua data bukutamu</title>
    </head>
    <body>
  <table width="550" border="1" cellpadding="0" cellspacing="1" bgcolor="#FFFF99">
            <tr>
                <td width="20"><b>No</b></td>
                <td width="111"><b>Nama</b></td>
                <td width="119"><b>Email</b></td>
                <td width="303"><b>Pesan</b></td>
                <td width="112"><b>Ip Address</b></td>
                <td width="88"><b>Menu</b></td>
            </tr>
<?php
include "koneksidb.php";
$kueri = "select * from tampil order by id";
$tampil = mysql_query($kueri);
while($data = mysql_fetch_array($tampil){
?>
 <tr bgcolor="#00FFFF">
                <td><?php echo $tampil ['id']; ?></td>
                <td><?php echo $tampil ['nama']; ?></td>
                <td><?php echo $tampil ['email']; ?></td>
                <td><?php echo $tampil ['pesan']; ?></td>
                <td><?php echo $tampil ['ip']; ?></td>
            </tr>
            <?php } ?>
        </table>
    </body>
</html>

7. Setelah semua siap mari kita tes
8. Simpan semua skripnya di localhost dan jalankan mulai dari bukutamu.php.

Sekian tutorial dari saya, pegel nulis satu tutor ini soalnya pake osk buat ngetiknya. Ciao!

Komentar

Postingan populer dari blog ini

Cara Install PHP Fusion di Android

Lagi iseng nyari script php buat website, eh malah nemu PHP Fusion. PHP Fusion, apa tuh? PHP Fusion adalah cms yang dapat digunakan untuk membuat website (mirip joomla atau wordpress). Biar lebih jelas cari aja di sourceforge.net Kenapa sih saya install di Android? Kenapa nggak di komputer aja kaya biasanya?

Cara Export Database Di PhpMyAdmin 4.1.14.1

Judul: Cara Export Database Di PhpMyAdmin 4.1.14.1 Author: ./MyHeartIsyr Disaat saya ingin export database yang saya punya saya menemukan masalah pada saat download file.sql

Where Have I Been? And Why Have I Not Write Anything for This Blog?

     So, where have I been for the past 6 years since my last post? Why have I not write anything for this blog? And also, why am I starts writing in English all of a sudden? Well, the reason why I haven't wrote anything for this blog is because I feel like I'm not good enough to write. Which is funny because I made this blog because I WANTED to write. And another reason is that I get bored from doing this very fast.      Then why even made this blog if you always gets bored to write? It all started from me buying a book about Blogger and blogging, the book talks about what blogger is, how can you make your own blog site with it, and it also talks a bit about blogging in general. The book was written somewhere in 2010-2011 (IIRC) and I bought it in 2017, after reading that book, all I could think about was how I wanted to make my own blog site. And from that, myheart-isyr.blogspot.com  was born.      I didn't have any writing skills back...