MEMBUAT GUEST BOOK SEDERHANA

MEMBUAT TABEL DI DATABASE MY-SQL

<?php

mysql_connect(“localhost”, “root”, “root”) or die(mysql_error());

mysql_select_db(“test”) or die(mysql_error());

mysql_query

(“CREATE TABLE example (

id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,

nama VARCHAR( 30 ) NULL ,

umur INT NULL)”)

or die(mysql_error());

echo “Tabel sudah dibuat”;

?>

MENGINPUT DATA DI TABEL

<?php

mysql_connect(“localhost”, “root”, “root”) or die(mysql_error());

mysql_select_db(“test”) or die(mysql_error());

mysql_query(“INSERT INTO example(nama, umur)

VALUES(‘budiman’, 20)”);

mysql_query(“INSERT INTO example(nama, umur)

VALUES(‘surti’, 30)”);

echo “Data sudah dimasukkan”;

?>

MENAMPILKAN DATA PADA DATABASE

<?php

mysql_connect(“localhost”, “root”, “root”) or die(mysql_error());

mysql_select_db(“test”) or die(mysql_error());

$hasil = mysql_query(“SELECT * FROM example”)

or die(mysql_error());

while ($record = mysql_fetch_array($hasil))

{

echo “Namanya: “.$record[‘nama’]. “<br>”;

echo “Umurnya: “.$record[‘umur’]. “<br><br>”;

}

?>

MEMBUAT FORM INPUTAN KE DATABASE

<body>

<h3>

<strong>INPUTAN DATA</strong>

</h3>

<table width=”200″ border=”1″>

<form name=”form1″ method=”post” action=”proses.php”>

<tr>

<td> Nama</td>

<td> <input type=”text” name=”nama”> </td>

</tr>

<tr>

<td>Umur</td>

<td><input type=”text” name=”umur”></td>

</tr>

<tr>

<td>&nbsp;</td>

<td> <input type=”submit” name=”Submit” value=”Submit”>

</td>

</tr>

</form>

</table>

</body>

FILE KONEKSI DAPAT DI PISAH DALAM FILE LAIN SELANJUTNYA DAPAT DI PANGGIL

<?

mysql_connect(“localhost”, “root”, “root”) or die(mysql_error());

mysql_select_db(“test”) or die(mysql_error());

?>

MENERIMA INPUTAN DARI FORM

<?

$nama = $_POST[‘nama’];

$umur = $_POST[‘umur’];

include “database.php”;

mysql_query(“INSERT INTO example(nama, umur)

VALUES(‘$nama’, $umur)”);

echo “Data sudah dimasukkan”;

?>

MENAMPILKAN DATA PADA DATABASE DALAM BENTUK TABEL

<?php

include”database.php”;

$hasil = mysql_query(“SELECT * FROM example”)

or die(mysql_error());

echo(“<table width=20% cellspacing=1 cellpadding=2 align=left bgcolor=#000000>”);

echo(“<tr><td bgcolor=#CCCCCC>Nama</td><td bgcolor=#CCCCCC>umur</td></tr>”);

while ($record = mysql_fetch_array($hasil))

{

echo(“<tr><td bgcolor=#FFFFFF>”.$record[‘nama’].”</td><td bgcolor=#FFFFFF>”.$record[‘umur’].”</td> </tr>”);

}

echo(“</table>”);

?>