TUGAS
PRAKTIKUM BASIS DATA
Diajukan
untuk memenuhi salah satu persyaratan mengikuti UTS Praktikum Basis Data
Oleh :
Alzani Saeful Anwar
1210705016
IF A
TEKNIK INFORMATIKA
FAKULTAS SAINS DAN TEKNOLOGI
UIN SUNAN GUNUNG DJATI
BANDUNG
2012
1. Login.php
<html>
<head>
<title>Login here</title>
<meta
http-equiv="content-Type" content="text/html;
charset=iso-8859-1">
<Style
type="text/CSS">
<!--
table{
font-family:
verdana, Arial, Helvetica, sans-serif;
font-size:
11px;
}
input{
font-family:
verdana, Arial, Helvetica, sans-serif;
font-size:
11px;
height:
20px;
}
-->
</style>
</head>
<body>
<div
align="center">
<form
action="Periksa.php" method="post"
name="login">
<table
width="286" border="0" cellpadding="0"
cellspacing="0">
<!--DWLayoutTable-->
<tr
bgcolor="#26b013">
<td
height="19" colspan="2" align="center"
valign="middle">
<font
color="#080f9e">LOGIN DI SINI</font></td>
</tr>
<tr>
<td
width="106" height="27"> </td>
<td
width="180"> </td>
</tr>
<tr>
<td
height="18" align="right"
valign="middle">username : </td>
<td
valign="middle">
<input
name="username" type="text" id="username"
size="20"></td>
</tr>
<tr>
<td
height="18" align="right"
valign="middle">password : </td>
<td
valign="middle">
<input
name="password" type="password" id="password"
size="20"></td>
</tr>
<tr>
<td
height="19"> </td>
<td></td>
</tr>
<tr>
<td
height="18"
valign="top"><!--DWLayoutEmptyCell--> </td>
<td
valign="middle">
<input
name="login" type="submit" id="login"
value="login "></td>
</tr>
<tr>
<td
height="28"> </td>
<td></td>
</tr>
<tr
bgcolor="#26b013">
<td
height="18" colspan="2"
valign="top"><!--DWLayoutEmptyCell--> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
2.
Periksa.php
<?php
session_start();
#*****************
Koneksi ke my sql *******************#
$host="localhost";
$user="root";
$pass="";
$dbname="latihan1";
$conn=mysql_connect($host,
$user, $pass);
if
($conn){
//select
database
$select
= mysql_select_db($dbname);
if
(!$select){
echo
mysql_error();
}
}
#*******************
akhir koneksi *********************#
#jika
ditekan tombol login
if (isset
($_POST['login'])){
$username=$_POST
['username'];
$password= $_POST ['password'];
$sql =
mysql_query("SELECT * FROM user WHERE username='$username' &&
password= '$password'");
$num =
mysql_num_rows($sql);
if ($num==1){
//login benar//
$_SESSION
['user']=$username;
$_SESSION ['passwd']=
$password;
?><script language
= "JavaScript">alert ('Anda Berhasil login');
document.location='Form_data.html'</script><?
} else {//jika login
salah//
?><script
language="JavaScript">alert ('Username document.location =
login.php'</script><?
}
}
?>
3.
Berhasil2.php
<?
$filecounter=
"counter.txt";
$fl=fopen($filecounter,"r+");
$hit=fread($fl,filesize($filecounter));
echo("<table
width=250 align=center border=1 cellspacing=0 cellpadding=0
bordercolor=#000FF><tr>");
echo("<td
width=250 valign=middle align=center>");
echo("<font
face=verdana size=2 color=#FF0000><b>");
echo("Anda
pengunjung yang ke:");
echo($hit);
echo("</b></font>");
echo("</td>");
echo("</tr></table>");
fclose($fl);
$fl=fopen($filecounter,"w+");
$hit=$hit+1;
fwrite($fl,$hit,strlen($hit));
fclose($fl);
?><br><br><br>
<html>
<head>
<html>
<head>
<title>Berhasil</title>
<meta
http-equiv="Content-type" content="text/html;
charset=iso-8859-1">
</head>
<body><center>
<table
width="746" border="0" cellpadding="0"
cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td
width="746" height="23" align="center"
valign="top"><font face="Verdana, Arial, Helvetica,
sans-serif">Selamat Datang <a
href="Logout.php">
<strong>LOGOUT</strong></a></font>
</td>
</tr>
<tr>
<td
heigt="88"> </td>
</tr>
<tr
align="center" valign="middle">
<td
height="33"><font color="#FF0000" size="5"
face="Arial, Helvetica, sans-serif">ANDA
BERHASIL
LOGIN !!</font></td>
</tr>
<tr>
<td
height="62"> </td>
</tr>
</table>
</center>
</body>
</html>
4.
Koneksi.php
<?php
$sambung=mysql_connect("localhost","root","");
if($sambung){
echo"koneksi
berhasil dilakukan.";
}else{echo"koneksi
gagal dilakukan.";}
?>
5.
Form_data.php
<html>
<head>
<title>
Form memasukkan data mahasiswa</title>
</head>
<body>
<table
border="0" width="63%" id="tabel" cellspacing="0">
<form
method="POST" action="tambah_data.php">
<tr>
<td width="198"
><font color="blue">NIM: </p></td>
<td> <input
type="text" name="nim" size="33"></td>
</tr>
<tr>
<td width="198"
><font color="blue">NAMA: </p></td>
<td> <input
type="text" name="nama" size="33"></td>
</tr>
<tr>
<td width="198"
><font color="blue">ALAMAT: </p></td>
<td> <input
type="text" name="alamat"
size="33"></td>
</tr>
<tr>
<td width="198"
><font color="blue">ANGKATAN: </p></td>
<td> <input
type="text" name="angkatan"
size="33"></td>
</tr>
<tr>
<td width="198"
> </td>
<td><input
type="submit" value="KIRIM"
name="submit"></td>
</tr>
</form>
</table>
</body>
6.
Tambah_data.php
<?php
//tambah
data.php
$sambung=mysql_connect("localhost","root","");
mysql_select_db("latihan1");
$nim=$_POST['nim'];
$nama=$_POST['nama'];
$alamat=$_POST['alamat'];
$angkatan=$_POST['angkatan'];
//perintah
memasukan data
$input="INSERT
INTO mahasiswa(nim,nama,alamat,angkatan)
VALUES('$nim','$nama','$alamat','$angkatan')";
//perintah
dilaksanakan
$hasil=mysql_query($input);
if($hasil){
echo"<br><br>DATA
mahasiswa telah dimasukkan.";
print("<td><a
href=Data_mahasiswa.php>Lihat Data</a></td>");
}else{
echo"<br><br>DATA
mahasiswa gagal dimasukkan.";}
?>
7.
Data_mahasiswa.php
<html>
<head>
<title>
data mahasiswa</title>
</head>
<body>
<CENTER><font
color="#26b013">DATA MAHASISWA</p></CENTER>
<br><br><br>
<table
align="center" border="1" width="82%"
cellspacing="1" cellpading="0" id="table1">
<tr>
<td align="center"
width="140">NIM</b></td>
<td align="center"
width="140">Nama</b></td>
<td align="center"
width="140">Alamat</b></td>
<td align="center"
width="140">Angkatan</b></td>
<td align="center"
width="140">Hapus</b></td>
</tr>
<?php
$sambung=mysql_connect("localhost","root","");
mysql_select_db("latihan1");
$hasil=mysql_query("select*from
mahasiswa");
while($data=mysql_fetch_array($hasil)){
$nim=$data[0];
$nama=$data[1];
$almt=$data[2];
$dt=$data[3];
print ("<tr>");
print("<td>$nim</td>");
print("<td>$nama</td>");
print("<td>$almt</td>");
print("<td>$dt</td>");
print("<td><a
href=hapus.php?id=".$data['NIM'].">hapus</a></td>");
print("</tr>");
}
?>
</table>
</body>
</html>
8.
Crate_table.php
<?php
$sambung=mysql_connect("localhost","root","");
if($sambung){
echo"koneksi
berhasil dilakukan.";
}else{echo"koneksi
gagal dilakukan.";}
mysql_select_db("latihan1",$sambung);
$sql="CREATE
TABLE telepon(
id
int not null primary key auto_increment,
nama
varchar(20),
telp
varchar(25))";
$hasil=mysql_query($sql,$sambung)
or die(mysql_error);
echo
$hasil;
?>
9.
Hapus.php
<?php
$sambung=mysql_connect("localhost","root","");
mysql_select_db("latihan1");
$sambung=$_GET['id'];
$sql="DELETE
FROM mahasiswa WHERE NIM='$sambung'";
$hasil=mysql_query($sql)
or die ("GAGAL");
if
($hasil){
header('location:Data_mahasiswa.php');
}
exit;
?>
10. Logout.php
<?php
session_start();
session_destroy();
header("Location: login.php?" .
"pesan=Silakan Login");
exit();
?>