Saturday, 24 May 2014

php & mysql

Tags
Membuat Buku Tamu dengan php mysql
a. Buatlah tabel bukutamu yang memiliki 3 field : nama, email, komentar.
Create table bukutamu (
nama char(20) not null,
email char(20),
komentar char (40)
);
b. Buat form untuk buku tamu, beri nama bukutamu.htm
<HTML>
<HEAD>
<title>Buku Tamu</title>
</HEAD>
<BODY>
<h1>Buku Tamu untuk database MySQL</h1>
<form action="bukutamu_add_form.php" method="post">
Nama : <input type="text" name="nama" size="35" maxlength="50"> <br>
Email : <input type="text" name="email" size="35" maxlength="50"> <br>
Komentar : <textarea name="komentar" rows="5" cols="30"></textarea> <br>
<input type="submit" value="Simpan">
<input type="reset" value="Reset">
</form>
</BODY>
</HTML>
c. Buat file bukutamu_add_form.php untuk memproses data dari bukutamu.htm dan menambahkan data ke tabel bukutamu.
<HTML>
<HEAD>
<title>Simpan Buku Tamu</title>
</HEAD>
<BODY>
<h1>Simpan Buku Tamu MySQL</h1>
<?
$nama = $_POST["nama"];
$email = $_POST["email"];
$komentar = $_POST["komentar"];
$conn=mysql_connect ("localhost","root","")
or die ("koneksi gagal");
mysql_select_db("faruq",$conn);
echo "Nama : $nama <br>";
echo "Email : $email <br>";
echo "Komentar : $komentar <br>";
$sqlstr="insert into bukutamu (nama,email,komentar)
values ('$nama','$email','$komentar')";
$hasil = mysql_query($sqlstr,$conn);
echo "Simpan bukutamu berhasil dilakukan";
?>
</BODY>
</HTML>
d. Buat file view.php untuk menampilkan isi buku tamu.
<?
$conn = mysql_connect("localhost","root","");
mysql_select_db("faruq",$conn);
$hasil = mysql_query("select * from bukutamu",$conn);
$jumlah = mysql_num_rows($hasil);
echo "<center>Daftar Pengunjung</center>";
echo "Jumlah pengunjung : $jumlah";
$a=1;
while($baris = mysql_fetch_array($hasil))
{
echo "<br>";
echo $a;
echo "<br>";
echo "Nama : ";
echo $baris[0];
echo "<br>";
echo "Email : ";
echo $baris[1];
echo "<br>";
echo "Komentar : ";
echo $baris[2];
$a++;
}
?>

php dengan mysql

Tags
LATIHAN – LATIHAN :
1. Menguji interkoneksi PHP dengan MySQL.
<html>
<head>
<title>Koneksi Database MySQL</title>
</head>
<body>
<h1>Demo koneksi database MySQL</h1>
<?
$conn=mysql_connect ("localhost","root","");
if ($conn) {
echo "OK";
} else {
echo "Server not connected";
}
?>
</body>
</html>



2. Melihat perbedaan antara mysql_fetch_array(), mysql_fetch_assoc(), mysql_fetch_row().

a. Buatlah tabel liga berikut ini, dengan 3 field : kode, negara, champion.

Create table liga (
kode char(3) not null,
negara char(15),
champion int
);

b. Isilah tabel dengan data berikut ini :

Insert into liga (kode, negara, champion)
values (‘jer’,’Jerman’,4);
Insert into liga (kode, negara, champion)
values (‘spa’,’Spanyol’,4);
Insert into liga (kode, negara, champion)
values (‘ing’,’Inggris’,3);
Insert into liga (kode, negara, champion)
values (‘bel’,’Belanda’,3);

c. Akses databases menggunakan mysql_fetch_array()
<HTML>
<HEAD>
<title>Koneksi Database MySQL</title>
</HEAD>
<BODY>
<h1>Koneksi database dengan mysql_fetch_array</h1>
<?
$conn=mysql_connect ("localhost","root","")
or die ("koneksi gagal");
mysql_select_db("faruq",$conn);
$hasil = mysql_query("select * from liga",$conn);
while ($row=mysql_fetch_array($hasil)) {
echo "Liga " .$row["negara"]; //array asosiatif
echo " mempunyai " .$row[2]; //array numeris
echo " wakil di liga champion <br>";
}
?>
</BODY>
</HTML>

d. Akses databases menggunakan mysql_fetch_assoc()
<HTML>
<HEAD>
<title>Koneksi Database MySQL</title>
</HEAD>
<BODY>
<h1>Koneksi database dengan mysql_fetch_assoc</h1>
<?
$conn=mysql_connect ("localhost","root","")
or die ("koneksi gagal");
mysql_select_db("faruq",$conn);
$hasil = mysql_query("select * from liga",$conn);
while ($row=mysql_fetch_array($hasil)) {
echo "Liga " .$row["negara"];
echo " mempunyai " .$row[“champion”];
echo " wakil di liga champion <br>";
}
?>
</BODY>
</HTML>

e. Akses databases menggunakan mysql_fetch_row()
<HTML>
<HEAD>
<title>Koneksi Database MySQL</title>
</HEAD>
<BODY>
<h1>Koneksi database dengan mysql_fetch_assoc</h1>
<?
$conn=mysql_connect ("localhost","root","")
or die ("koneksi gagal");
mysql_select_db("faruq",$conn);
$hasil = mysql_query("select * from liga",$conn);
while ($row=mysql_fetch_row($hasil)) {
echo "Liga " .$row[1];
echo " mempunyai " .$row[2];
echo " wakil di liga champion <br>";
}
?>
</BODY>
</HTML>



Friday, 16 May 2014

css contoh layout

Tags
 dalam tutorial ini saya akan memberikan source code membuat layout simple dengan Css dan kalian dapat  memodifikasinya :
<html>
<head>
<title> membuat layout web dengan css </title>
<style>
#head-container
{
color: #000;
background: #8EB3DB;
}
#header
{
margin: 0 auto;
width: 860px;
padding: 20px;
background: #DAE6F3;
}
#header h1 { margin: 0; }
#navigation-container
{
float: left;
width: 100%;
color: #000;
background: #369FE0;
}
#navigation
{
margin: 0 auto;
width: 900px;
}
#navigation ul
{
margin: 0;
padding: 0;
}
#navigation ul li
{
list-style-type: none;
display: inline;
}
#navigation li a
{
display: block;
float: left;
padding: 5px 10px;
color: #fff;
text-decoration: none;
border-right: 1px solid #fff;
}
#navigation li a:hover { background: #257BB4; }
#content-container
{
float: left;
width: 100%;
color: #000;
background: #F7F9FC;
}
#content-container2
{
margin: 0 auto;
width: 900px;
}
#content-container3
{
float: left;
width: 900px;
background: #FFF url(two-fixed-background.gif) repeat-y 100% 0;
}
#content
{
clear: left;
float: left;
width: 560px;
padding: 20px 0;
margin: 0 0 0 30px;
display: inline;
}
#content h2 { margin: 0; }
#right
{
float: right;
width: 240px;
padding: 20px 0;
margin: 0 20px 0 0;
display: inline;
}
#right h3 { margin: 0; }
#footer-container
{
clear: left;
color: #fff;
background: #3399ff;
}
#footer
{
margin: 0 auto;
width: 900px;
text-align: right;
padding: 20px;
height: 1%;
}
</style>
</head>
<body>
<div id=”head-container”>
<div id=”header”>
<h1>
</h1>
</div>
</div>
<div id=”navigation-container”>
<div id=”navigation”>
<ul>
<li><a href=”#”>Home</a></li>
<li><a href=”#”>About</a></li>
<li><a href=”#”>Services</a></li>
<li><a href=”#”>Contact us</a></li>
</ul>
</div>
</div>
<div id=”content-container”>
<div id=”content-container2″>
<div id=”content-container3″>
<div id=”content”>
<h2>
This is Page heading
</h2>
<p>
This is paragraph 1
</p>
<p>
This is paragraph 2
</p>
<p>
This is paragraph 3
</p>
</div>
<div id=”right”>
<h3>
Right heading
</h3>
<p>
This is paragraph 1
</p>
</div>
</div>
</div>
<div id=”footer-container”>
<div id=”footer”>
Copyright © nama web kamu, 2010
</div>
</div>
</div>
</body>
</html>





css contoh layout

Tags
 dalam tutorial ini saya akan memberikan source code membuat layout simple dengan Css dan kalian dapat  memodifikasinya :
<html>
<head>
<title> membuat layout web dengan css </title>
<style>
#head-container
{
color: #000;
background: #8EB3DB;
}
#header
{
margin: 0 auto;
width: 860px;
padding: 20px;
background: #DAE6F3;
}
#header h1 { margin: 0; }
#navigation-container
{
float: left;
width: 100%;
color: #000;
background: #369FE0;
}
#navigation
{
margin: 0 auto;
width: 900px;
}
#navigation ul
{
margin: 0;
padding: 0;
}
#navigation ul li
{
list-style-type: none;
display: inline;
}
#navigation li a
{
display: block;
float: left;
padding: 5px 10px;
color: #fff;
text-decoration: none;
border-right: 1px solid #fff;
}
#navigation li a:hover { background: #257BB4; }
#content-container
{
float: left;
width: 100%;
color: #000;
background: #F7F9FC;
}
#content-container2
{
margin: 0 auto;
width: 900px;
}
#content-container3
{
float: left;
width: 900px;
background: #FFF url(two-fixed-background.gif) repeat-y 100% 0;
}
#content
{
clear: left;
float: left;
width: 560px;
padding: 20px 0;
margin: 0 0 0 30px;
display: inline;
}
#content h2 { margin: 0; }
#right
{
float: right;
width: 240px;
padding: 20px 0;
margin: 0 20px 0 0;
display: inline;
}
#right h3 { margin: 0; }
#footer-container
{
clear: left;
color: #fff;
background: #3399ff;
}
#footer
{
margin: 0 auto;
width: 900px;
text-align: right;
padding: 20px;
height: 1%;
}
</style>
</head>
<body>
<div id=”head-container”>
<div id=”header”>
<h1>
</h1>
</div>
</div>
<div id=”navigation-container”>
<div id=”navigation”>
<ul>
<li><a href=”#”>Home</a></li>
<li><a href=”#”>About</a></li>
<li><a href=”#”>Services</a></li>
<li><a href=”#”>Contact us</a></li>
</ul>
</div>
</div>
<div id=”content-container”>
<div id=”content-container2″>
<div id=”content-container3″>
<div id=”content”>
<h2>
This is Page heading
</h2>
<p>
This is paragraph 1
</p>
<p>
This is paragraph 2
</p>
<p>
This is paragraph 3
</p>
</div>
<div id=”right”>
<h3>
Right heading
</h3>
<p>
This is paragraph 1
</p>
</div>
</div>
</div>
<div id=”footer-container”>
<div id=”footer”>
Copyright © nama web kamu, 2010
</div>
</div>
</div>
</body>
</html>