Anda di halaman 1dari 2

Simpan Dengan nama input.

php
<html>
<head><title>Form Input Data Mahasiswa</title>
</head>
<body> <center>
<form method='post'>
</br>
</br>
<table width="200" border="1">
<tr>
<th scope="row">NIM</th>
<td><input type="text" name="nim" ></td>
</tr>
<tr>
<th scope="row">Nama</th>
<td><textarea name="nama" cols="50" rows="1"></textarea></td>
</tr>
<tr>
<th scope="row">Prodi</th>
<td><input name="prodi" type="text"></td>
</tr>
<tr>
<th scope="row">Alamat</th>
<td><textarea name="alamat" cols="80" rows="1"></textarea></td>
</tr>
</table>
<br>
<a href="daftarmahasiswa.php">Lihat Daftar Mahasiswa</a>
</br>
<pre><input type="submit" value="Simpan" name="submit"></pre>
</form>
<?php
$koneksi=mysql_connect("localhost","root","");
mysql_select_db("dbakademik");
if($_REQUEST['submit']){
$NI=$_REQUEST['nim'];
$NA=$_REQUEST['nama'];
$PROD=$_REQUEST['prodi'];
$ALM=$_REQUEST['alamat'];
$qry="insert into mahasiswa(nim,nama,prodi,alamat) values
('$NI','$NA','$PROD','$ALM')";
$hasil=mysql_query($qry,$koneksi);
if($hasil)
{
echo "Proses Simpan Sukses";
}
}
?>
</center>
</body>
</html>
Simpan dengan nama daftarmahasiswa.php

<html>
<head><title>Halaman Daftar Mahasiswa</title></head>
<body> <center>
<h1><b>Daftar Mahasiswa</b></h1>
<pre><p><strong>
<a href="input.php">Back To Input</a>
</strong></p></pre>
</br>
</br>
</br>
<?php
$koneksi=mysql_connect("localhost","root","");
mysql_select_db("dbakademik");
$qry ='select * from mahasiswa order by nim Asc';
$hasil=mysql_query($qry,$koneksi);
echo"<table border=1>";
echo"<tr><td><center><b>NIM</b></center></td>
<td><center><b>NAMA</b></center></td>
<td><center><b>PRODI</b></center></td>
<td><center><b>ALAMAT</b></center></td></tr>";
while ($baris=mysql_fetch_array($hasil)){
echo "<tr>
<td>".$baris['nim']."</td>
<td>".$baris['nama']."</td>
<td>".$baris['prodi']."</td>
<td>".$baris['alamat']."</td>
<td><a href='editmahasiswa.php?nim=".$baris['nim']."'>
Edit</a></td>
<td><a href='delmahasiswa.php?nim=".$baris['nim']."'>
Delete</a></td></tr>";
}
?>
</body>
</center>
</html>

Anda mungkin juga menyukai