Created
January 7, 2020 04:05
-
-
Save dwijonarko/37b9e6fdcc505f6e02c5203e50fb2781 to your computer and use it in GitHub Desktop.
CRUD Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css"> | |
<script src="../bootstrap/js/bootstrap.min.js"></script> | |
<title>Form Mahasiswa</title> | |
</head> | |
<body> | |
<div class="container" style="padding-top: 65px;"> | |
<h2>Form Biodata</h2> | |
<form action="" method="post" class="form form-horizontal"> | |
<div class="form-group row"> | |
<label for="nim" class="col-sm-2 col-form-label">Nomor Induk</label> | |
<div class="col-sm-10"> | |
<input type="text" class="form-control" name="nim" id="nim" placeholder="Nomor Induk"> | |
</div> | |
</div> | |
<div class="form-group row"> | |
<label for="nama" class="col-sm-2 col-form-label">Nama</label> | |
<div class="col-sm-10"> | |
<input type="text" class="form-control" name="nama" id="nama" placeholder="Nama"> | |
</div> | |
</div> | |
<div class="form-group row"> | |
<label for="tempat_lahir" class="col-sm-2 col-form-label">Tempat Lahir</label> | |
<div class="col-sm-10"> | |
<input type="text" class="form-control" name="tempat_lahir" id="tempat_lahir" placeholder="Tempat Lahir"> | |
</div> | |
</div> | |
<div class="form-group row"> | |
<label for="tanggal_lahir" class="col-sm-2 col-form-label">Tanggal Lahir</label> | |
<div class="col-sm-10"> | |
<input type="date" class="form-control" name="tanggal_lahir" id="tanggal_lahir" placeholder="Tempat Lahir"> | |
</div> | |
</div> | |
<div class="form-group row"> | |
<label for="agama" class="col-sm-2 col-form-label">Agama</label> | |
<div class="col-sm-10"> | |
<select name="agama" id="agama" class="form-control"> | |
<option value="islam">Islam</option> | |
<option value="kristan">Kristen</option> | |
<option value="katolik">Katolik</option> | |
<option value="hindu">Hindu</option> | |
<option value="budha">Budha</option> | |
</select> | |
</div> | |
</div> | |
<div class="form-group row"> | |
<label for="jurusan" class="col-sm-2 col-form-label">Jurusan</label> | |
<div class="col-sm-10"> | |
<select name="jurusan" id="jurusan" class="form-control"> | |
<option value="ti">Teknik Informatika</option> | |
<option value="tt">Teknik Telekomunikasi</option> | |
<option value="tm">Teknik Mekatronika</option> | |
</select> | |
</div> | |
</div> | |
<div class="form-group row"> | |
<label for="alamat" class="col-sm-2 col-form-label">Alamat</label> | |
<div class="col-sm-10"> | |
<textarea name="alamat" id="alamat" class="form-control"></textarea> | |
</div> | |
</div> | |
<div class="form-group row"> | |
<label for="email" class="col-sm-2 col-form-label">Email</label> | |
<div class="col-sm-10"> | |
<input type="email" name="email" class="form-control"> | |
</div> | |
</div> | |
<div class="form-group row"> | |
<input type="submit" name="simpan" value="Simpan" class="btn btn-primary"> | |
</div> | |
</form> | |
</div> | |
<?php | |
if (isset($_POST['simpan']) && !empty($_POST)) { | |
include("koneksi.php"); | |
$nim = $conn->real_escape_string($_POST['nim']); | |
$nama = $conn->real_escape_string($_POST['nama']); | |
$tempat_lahir = $conn->real_escape_string($_POST['tempat_lahir']); | |
$tanggal_lahir = $conn->real_escape_string($_POST['tanggal_lahir']); | |
$agama = $conn->real_escape_string($_POST['agama']); | |
$jurusan = $conn->real_escape_string($_POST['jurusan']); | |
$alamat = $conn->real_escape_string($_POST['alamat']); | |
$email = $conn->real_escape_string($_POST['email']); | |
$sql = "INSERT INTO mahasiswa (nim,nama,tempat_lahir,tanggal_lahir,agama,jurusan,alamat,email) VALUES ('$nim','$nama','$tempat_lahir','$tanggal_lahir','$agama','$jurusan','$alamat','$email')"; | |
if($conn->query($sql)===TRUE){ | |
echo "<div class='alert alert-success'>New record created successfully</div>"; | |
header("Refresh:3, url=mahasiswa.php"); | |
}else{ | |
echo "<div class='alert alert-danger'>Error: " . $sql . "<br>" . $conn->error."</div>"; | |
} | |
$conn->close(); | |
} | |
?> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//koneksi.php | |
$server="localhost"; | |
$user="root"; //user mysql | |
$password="root"; //password mysql | |
$db="8113190001"; //nama database | |
$conn = new mysqli($server,$user,$password,$db); | |
if($conn->connect_error){ | |
die("Connection failed ".$conn->connect_error); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css"> | |
<script src="../bootstrap/js/bootstrap.min.js"></script> | |
<title>Mahasiswa</title> | |
</head> | |
<body class="container" style="padding-top: 65px;"> | |
<?php | |
include('koneksi.php'); | |
$sql = "SELECT * FROM mahasiswa"; | |
$results = $conn->query($sql); | |
$rows = $results->fetch_all(MYSQLI_ASSOC); | |
?> | |
<h2>Data mahasiswa</h2> | |
<table class="table"> | |
<tr> | |
<th>NIM</th> | |
<th>Nama</th> | |
<th>Tempat Lahir</th> | |
<th>Tanggal Lahir</th> | |
</tr> | |
<?php foreach($rows as $mahasiswa) : ?> | |
<tr> | |
<td><?php echo $mahasiswa['nim']?></td> | |
<td><?php echo $mahasiswa['nama']?></td> | |
<td><?php echo $mahasiswa['tempat_lahir']?></td> | |
<td><?php echo $mahasiswa['tanggal_lahir']?></td> | |
</tr> | |
<?php endforeach ?> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment