Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add.php
- <html>
- <head>
- <title>Insert Data Mahasiswa</title>
- </head>
- <body>
- <form method="post" action="insert.php">
- <table border="1" cellpadding="5" cellspacing="0">
- <tr bgcolor="silver">
- <td colspan="3" align="center"><h3>DATA MAHASISWA</h3>
- </td>
- </tr>
- <tr>
- <td>NIM</td>
- <td>:</td>
- <td><input type="text" name="txtnim" size="10" /></td>
- </tr>
- <tr>
- <td>Nama</td>
- <td>:</td>
- <td><input type="text" name="txtnama" size="50" /></td>
- </tr>
- <tr>
- <td>Umur</td>
- <td>:</td>
- <td><input type="text" name="txtumur" size="5" /></td>
- </tr>
- <tr>
- <td>Gender</td>
- <td>:</td>
- <td><input type="radio" name="rdogender" value="PRIA" />PRIA<input type="radio" name="rdogender" value="WANITA" />WANITA</td>
- </tr>
- <tr align="center">
- <td colspan="3">
- <input type="submit" value="OKE" />
- <input type="reset" value="BATAL" />
- <?php
- echo "\t [<a href=view.php>Lihat Data Mahasiswa</a>]";
- ?>
- </td>
- </tr>
- </table>
- </form>
- </body>
- </html>
- koneksi.php
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "akademik";
- // Create connection
- $koneksi = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$koneksi) {
- die("Connection failed: " . mysqli_connect_error());
- }
- $sql = "SELECT * FROM mahasiswa";
- $result = mysqli_query($koneksi, $sql) or die (mysqli_error());
- echo '<table border="5">';
- echo '<tr bgcolor="#006600">';
- echo '<td>Nim</td>';
- echo '<td>Nama</td>';
- echo '<td>Umur</td>';
- echo '<td>Gender</td>';
- echo '</tr>';
- if (mysqli_num_rows($result) > 0) {
- // output data of each row
- while($row = mysqli_fetch_array($result)) {
- echo "<tr>";
- echo "<td>$row[0]</td>";
- echo "<td>$row[1]</td>";
- echo "<td>$row[2]</td>";
- echo "<td>$row[3]</td>";
- echo "</tr>";
- }
- mysqli_free_result($result);
- } else {
- echo "0 results".mysqli_error();
- }
- //mysqli_close($koneksi);
- ?>
- insert.php
- <html>
- <head>
- <title>Insert Data Mahasiswa</title>
- </head>
- <body>
- <?php
- include "koneksi.php";
- if($koneksi)
- {
- $nama= (isset($_POST['txtnama']))? $_POST['txtnama']: '';
- $nim= (isset($_POST['txtnim']))? $_POST['txtnim']: '';
- $umur= (isset($_POST['txtumur']))? $_POST['txtumur']: '';;
- $gender= (isset($POST['rdogender']))? $_POST['rdogender']: '';
- $sql = "INSERT INTO mahasiswa Values('$nim','$nama','$umur','$gender')";
- mysqli_query($koneksi,$sql) or die ("Proses Insert data GAGAL! <br> mysqli_error()");
- echo "Proses Insert data Berhasil";
- echo "<br>";
- echo "[<a href=view.php>Lihat Data Mahasiswa</a>]";
- }
- ?>
- </body>
- </html>
- view.php
- <html>
- <head>
- <title>Tampil Data Mahasiswa</title>
- <script language="javascript">
- function konfirmasi(nim)
- {
- tanya = confirm('Anda Yakin Ingin Menghapus Data Mahasiswa Dengan Nim'+nim+'?');
- if(tanya == true) return true;
- else return false;
- }
- </script>
- </head>
- <body>
- <?php
- include ("koneksi.php");
- $perintah_sql = "SELECT * FROM mahasiswa ORDER BY nim";
- mysqli_select_db($koneksi,$dbname) or die ("GAGAL Memilih DataBase");
- $hasil_query = mysqli_query($koneksi,$perintah_sql) or die (mysqli_error());
- $jumlah_data = mysqli_num_rows($hasil_query);
- echo "<h3>DATA MAHASISWA</h3>";
- echo "<table border=1 cellpadding=2 cellspacing=0>";
- echo '<tr bgcolor="silver" align="center">';
- echo '<td>Nim</td>';
- echo '<td>Nama</td>';
- echo '<td>Umur</td>';
- echo '<td>Gender</td>';
- echo '<td colspan=2>AKSI</td>';
- echo '</tr>';
- while($row=mysqli_fetch_array($hasil_query))
- {
- echo '<tr>';
- echo '<td>$row[0]</td>';
- echo '<td>$row[1]</td>';
- echo '<td>$row[2]</td>';
- echo '<td>$row[3]</td>';
- echo '<td><a href=\"delete.php?nim=$row[0]\">Ubah</a></td>';
- echo "<td><a href=\"delete.php?nim=$row[0]\"onclick=\"return konfirmasi('".$row[0]."')\">Hapus</a></td>";
- echo '</tr>';
- }
- echo "</table>";
- echo "Jumlah Data : $jumlah_data \t [<a href=add.php>Tambah Data</a>]";
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement