Pada pertemuan kali ini kita akan membahas tentang aplikasi pengolah data menggunakan PHP. simpan dengan nama aplikasi.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>Aplikasi Tabel PHP</title>
<link rel="stylesheet" href="login.css" type="text/css"/>
</head>
<body>
<div id="form">
<h2 align="center">Data Mahasiswa</h2>
<hr style="color:#3ebee9; border:double;" align="center" width="300"/>
<form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
<div id="Input">
No:<br /> <input type="text" name="no"/><br />
Nama:<br /> <input type="text" name="nama"/><br />
Alamat:<br /> <input type="text" name="alamat"/><br />
</div>
<div id="btnLogin">
<input type="submit" name="OK" value="OK"/>
</div>
</form>
</div>
<?php
$id=mysql_connect("localhost", "root", "");
$db=mysql_select_db("mahasiswa",$id);
if(!$db)
echo "gagal<br>";
else
echo "berhasil koneksi ke data base<br>";
echo("<table width=250 align=center border=1 cellspacing=0 cellpadding=0 bordercolor=#0000FF><tr>");
echo("<th align='center'>No</th>");
echo("<th align='center'>Nama</th>");
echo("<th align='center'>Alamat</th>");
if (isset($_POST['OK'])){
$no = $_POST['no'];
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$proses = "insert into nama set no ='$no', nama='$nama',
alamat='$alamat'";
$simpan= mysql_query($proses);
if ($simpan) {
echo "<font size=5>Data Disimpan </font><br>";
}else{
echo "<font size=5>Data Gagal Disimpan </font><br>";
}
}
$hasil = mysql_query("select* from nama", $id);
while($row=mysql_fetch_array($hasil)){
$isino = $row["no"];
$isinama=$row["nama"];
$isialamat=$row["alamat"];
echo("<tr><td align='center'>$isino</td>");
echo("<td align='center'>$isinama</td>");
echo("<td align='center'>$isialamat</td></tr>");
}
?>
</body>
</html>
0 comments:
Posting Komentar