- KONEKSI.html
<html>
<head> <title>latihan koneksi</title> </head>
<body>
<form action="koneksi.php" method="post">
<table>
<tr>
<td colspan="2"><center>FORM DATA</centre></td>
</tr>
<tr>
<td>NAMA</td>
<td><input type="text" name="nama"></td>
</tr>
<tr>
<td>KELAS</td>
<td>
<select name="kelas">
<option>XIA1</option>
<option>XIA2</option>
<option>XIA3</option>
<option>XIA4</option>
</select>
</td>
</tr>
<tr>
<td>EMAIL</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" value="SUBMIT"></center><td>
</tr>
</table>
</form>
</body>
</html>
- SHOW.php
<?php
$koneksi=mysql_connect("localhost","root","") or die("koneksi mysql gagal")
mysql_select_db("vania_XIS1_koneksi",$koneksi) or die("database selected fail");
$perintah="select *from data_pelanggan;";
$hasil=mysql_query($perintah);
echo"
<html>
<head> <title> LATIHAN KONEKSI </title> </head>
<body>
<table border=1>
<tr>
<td>NAMA</td>
<td>KELAS</td>
<td>EMAIL</td>
</tr>
";
while($baris=mysql_fetch_row($hasil))
{
echo"
<tr>
<td>$baris[0]</td>
<td>$baris[1]</td>
<td>$baris[2]</td>
</tr>
";
}
echo"
</table>
</body>
</html>
";
?>
- KONEKSI.php
<?php
$nama=$_POST['nama'];
$kelas=$_POST['kelas'];
$email=$_POST['email'];
$koneksi=mysql_connect ("localhost","root","") or die("Koneksi mysql error");
mysql_select_db("vania_XIS1_koneksi",$koneksi) or die("koneksi database error");
$perintah="insert into data_pelanggan values('$nama','$kelas','$email');";
mysql_query($perintah,$koneksi) or die("mysql_query sending failed");
mysql_close($koneksi);
?>
Tidak ada komentar:
Posting Komentar