Senin, 20 Mei 2013

Pemograman Web Lanjut (PWL) 02

nih yuda saya share PWL nya,
udah jangan berisik lagi ya.. :)


saya ambil yang paling sederhana aja dah,, hehe :D
gomen nasai. :D

lngsng aja, :)

sebelum nya buat database dengan nama siswa dan nama table nya data .
buat form.php
<html>
<head>
<title> input data</title>
</head>
<body>
<form method='POST' action='save.php'>
nama : <input type='text' name='nama'><br>
kelas : <input type='text' name='kelas'><br>
<input type='submit' value='submit'>
</form>
</body>
</html>



save.php

<?php
include('koneksi.php');

$nama=$_POST['nama'];
$kelas=$_POST['kelas'];

$query="insert into data(nama,kelas) values ('$nama','$kelas')";
$hasil=mysql_query($query);
if($hasil){
echo " input data berhasil<br> <a href='lihat.php'>lihat hasil</a>";
}else{
echo " gagal input data ";
}
?>

koneksi.php

<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'siswa';

mysql_connect($host,$user,$pass) or die('gagak konek ke server');
mysql_select_db($db) or die ('database gak ditemukan');
?>

terakhir. lihat.php

<html>
<head>
<title>hasil input data</title>
</head>
<body>
<table border='1' align='center'>
<tr>
<td width="21"> Id</td>
<td width="147"> Nama</td>
<td width="87"> Kelas</td>
<td width="87"> Update</td>
</tr>

<?php
include('koneksi.php');

$query=mysql_query("select * from data;");
while($a=mysql_fetch_array($query)){
?>
<tr>
<td><?php echo $a['id']; ?></td>
<td><?php echo $a['nama']; ?></td>
<td><?php echo $a['kelas']; ?></td>
<td width="200"><a href="edit.php?id=<?php echo $a['id']; ?>">edit</a> | <a href="hapus.php?id=<?php echo $a['id']; ?>">hapus</a>
</tr>
<?php } ?>
</table>
</body>
</html>

NOTE : YANG EDIT SAMA DELETE NYA NANTI AJA YA... CARI NGETIK SAYA :D
udah tuh,, semoga berhasil ya..:)

arigatou gozaimasu

Tidak ada komentar:

Posting Komentar