You are on page 1of 4

Index.

php

<!DOCTYPE html>

<html>

<head>

<title>Tambah Data</title>

</head>

<body>

<h1>Data Siswa SMK Inovasi Mandiri</h1>

<a href="tambahdata.php">Tambah Data </a><br><br>

<table border="1" cellspacing="0" cellpadding="3">

<tr>

<th>No.</th>

<th>Nis</th>

<th>Nama</th>

<th>alamat</th>

<th>Jurusan</th>

<th>No Hanphone</th>

</tr>

<?php

include "koneksi.php";

$no=1;

$ambildata = mysqli_query($koneksi, "select * from siswa");

while ($tampil = mysqli_fetch_array($ambildata)){

echo"

<tr>

<td>$no</td>

<td>$tampil[nis]</td>
<td>$tampil[nama]</td>

<td>$tampil[alamat]</td>

<td>$tampil[jurusan]</td>

<td>$tampil[no_hp]</td>

</tr>";

$no++;

?>

</table>

</body>

</html>

Koneksi.php

<?php

$koneksi = mysqli_connect("localhost","root","","db_latihan");

// Check connection

if (mysqli_connect_errno()){

echo "Koneksi database gagal : " . mysqli_connect_error();

?>
tambahdata.php

include "koneksi.php";

if(isset($_POST["tambah"]) ){
$nis = $_POST["nis"];
$nama = $_POST["nama"];
$alamat = $_POST["alamat"];
$jurusan = $_POST["jurusan"];
$no_hp = $_POST["no_hp"];

$query ="INSERT INTO siswa Value('','$nis','$nama','$alamat','$jurusan','$no_hp')";

mysqli_query($koneksi, $query);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tambah Data Siswa</title>
</head>
<body>
<h1>Tambah Data Siswa</h1>
<form action="" method="post">
<label for="nis">NIS :</label>
<input type="text" name="nis" id="nis" placeholder="Masukan Nis"><br>
<label for="nama">Nama :</label>
<input type="text" name="nama" id="nama" placeholder="Masukan Nama"><br>
<label for="alamat">Alamat :</label>
<input type="text" name="alamat" id="nis" placeholder="Masukan Alamat"><br>
<label for="jurusan">Jurusan :</label>
<input type="text" name="jurusan" id="jurusan" placeholder="Masukan Jurusan"><br>
<label for="no_hp">No Handphone :</label>
<input type="text" name="no_hp" id="no_hp" placeholder="Masukan No Hanphone"><br>
<button type="submit" name="tambah">Simpan</button> <br><br><br>

<a href="index.php">Kembali</a>

</body>
</html>
CREATE TABLE `siswa` (

`id` int(5) NOT NULL,

`nis` varchar(12) NOT NULL,

`nama` varchar(50) NOT NULL,

`alamat` varchar(100) NOT NULL,

`jurusan` text NOT NULL,

`no_hp` varchar(100) NOT NULL

You might also like