Cara Membuat Crud Biodata dengan PHP dan Mysql Xampp 2018
Assalamaulaikum Guys Selamat siang . sore malama mapun pagi.
Pada psotingan kali ini ada cara membuat crud biodata dengan php mysql . yuk langsung saj apa saja bahannya oh iya ini gambaran nanti jadinya script curd
Karena ini adalah versi 2018 maka script crud dalam php mysql di xampp yang admin gunakan ya versi 2018 . bahan yang pertama pastinya aplikasi Xampp versi nterbaru download di situ resminya
1. Download Xampp
2. Web Browser -> Bisa Chrome atau mozila firefox
3. Download Sublime Text atau Editor bahsa pmorgamn laiinnya
Oke cuma itu bahnnya sekarang kita buat crud biodatanya
langkah - langkah
1. Install Xampp control panel . Jika sudah. Mak Aktifkan Fitur MYSQL DAN APACHE di xampp
<!DOCTYPE html>
<html>
<head>
<title>Belajar PHP CRUD</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<body bgcolor="#800000">
<font face="tohama" color="cyan"><h1 align="center">DATA SISWA LOMBA KOMPETENSI SISWA</font></p></h1>
<a href="tambah.php"><p align="center"><img src="input.png" align="center"></a></p>
<!-- <a href="tambah.php">+ TAMBAH MAHASISWA</a> -->
<table class="tbl-qa" align="center">
<thead>
<tr>
<th class="table_header" wnimmhsth="20%" align="center">NO</th>
<th class="table_header" wnimmhsth="20%" align="center">Nama</th>
<th class="table_header" wnimmhsth="20%" align="center">NIS</th>
<th class="table_header" wnimmhsth="20%" align="center">Alamat</th>
<th class="table_header" wnimmhsth="20%" align="center">Jurusan</th>
<th class="table_header" wnimmhsth="20%" colspan="2" align="center">Aksi</th>
</tr>
</thead>
<?php
include "koneksi1.php";
$no = 1;
$data = mysqli_query ($con,"select * from 1_siswa");
while ($d = mysqli_fetch_array ($data)){
?>
<tr class="table-row">
<td class="table-row"><?php echo $no++; ?></td>
<td class="table-row"><?php echo $d['nama'];
?></td>
<td class="table-row"><?php echo $d['nis'];
?></td>
<td class="table-row"><?php echo $d['Alamat'];
?></td>
<td class="table-row"><?php echo $d['jurusan'];
?></td>
<td class="table-row">
<a href="edit.php?id=<?php echo $d['id'];
?>"><img src="oyi.png"></a></td>
<td class="table-row">
<a href="hapus.php?id=<?php echo $d['id']; ?>"
onClick="return confrim ('Apakah Anda yakin Ingin Menghapus Data?')"/><img src="delet.png">
</a></td>
<!-- <a href="hapus.php?id=<?php echo $d['id'];?>">HAPUS</a> -->
</td>
</tr>
<?php
}
?>
</table>
<p align="center"><font size="3" face="Bodoni MT" color="white">©Abdulloh Aqil 2018</p></font>
</body>
</html>
Script Ke dua untuk Koneksi database ke php Koneksi 1.php
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "db_akademik";
$con = mysqli_connect($host,$user,$pass); mysqli_select_db($con, $db);
// Cek koneksi
if (mysqli_connect_error()){
echo "Koneksi database gagal : " . mysqli_connect_error();
}
?>
ada script cssnya
style.css
tbl-qa{width: 50%;font-size:0.9em;background-color: #6ab5b9;border-spacing:
1px;border-radius: 4px;}
.tbl-qa.table-header th {padding:5px;text-align:left;padding:10px;background-color:#E6E6FA;font-weight:normal;}
.tbl-qa .table-row td {padding:10px;background-color: #ADFF2F;vertical-align:top;}
.button_link {padding: 20px 0px;}
.button_link a{color: #000000;text-decoration: none;background-color:
#7FFFD4;padding: 8px 20px;font-size: 0.8em;border: #428a8e 1px solid; border-radius: 4px;}
.message { color: #FF0000;
text-align: center; width: 100%;
}
.txtField {padding: 8px;border: #afced0 1px solid;border-radius: 4px;width: 250px;}
.demo-form-submit {color: #FFF;background-color: #4e7173;padding: 10px
50px;border: 0px;cursor: pointer;border-radius:4px;}
.message { padding:8px 10px;box-sizing: border-box;text-align: left;border-radius: 4px;}
.success {background-color: #c4e4c4;border: #9ac19a 1px solid;color: #4b8e4b;}
.error {background-color: #e4cbc4;border: #c19c9a 1px solid;color: #8e4e4b;}
css_siswa.css
table, th, td {
border: 1px solid black; border-collapse: collapse;
}
th, td {
padding: 5px; text-align: left;
}
input[type=text], select { width: 100%;
padding: 12px 20px; margin: 8px 0; display: inline-block; border: 1px solid #ccc; border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] { width: 100%;
background-color: #4CAF50; color: white;
padding: 14px 20px;
margin: 8px 0; border: none; border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover { background-color: #45a049;
}
div {
border-radius: 5px; background-color: #f2f2f2; padding: 20px;
}
section { width: 80%;
padding: 20px; margin: 20px auto;
background-color: white;
}
h1 {
color: #F30;
font-size: 36px;
}
nav{
background-color: #4CAF50; color: #fff;
height: 60px; margin: 10px 0;
}
nav a{ float: left;
padding: 20px; height: 20px;
text-decoration: none; color: #FFF;
}
nav a:hover {
background-color: #1f663a;
}
article {
min-height: 20px; color: #333;
}
footer {
text-align: center; display: block; margin-button: 10px;
}
Pada psotingan kali ini ada cara membuat crud biodata dengan php mysql . yuk langsung saj apa saja bahannya oh iya ini gambaran nanti jadinya script curd
Karena ini adalah versi 2018 maka script crud dalam php mysql di xampp yang admin gunakan ya versi 2018 . bahan yang pertama pastinya aplikasi Xampp versi nterbaru download di situ resminya
1. Download Xampp
2. Web Browser -> Bisa Chrome atau mozila firefox
3. Download Sublime Text atau Editor bahsa pmorgamn laiinnya
Oke cuma itu bahnnya sekarang kita buat crud biodatanya
langkah - langkah
1. Install Xampp control panel . Jika sudah. Mak Aktifkan Fitur MYSQL DAN APACHE di xampp
2. Jika sudah aktif langsung buka web browser dan ketikkan localhost/phpmyadmin
3. Langusng pilih new
4. Buat database
Klik Create
Klik Go
Isi sesuai gambar tak susuai juga tidak apa apa karena itu panjang karakter
Centang A_I Dan pilih Primary
5. Masukkan data sebagai demo nanti crud biodata
Data di masukan
Sudah masuk data base
5. Membuat scritp crud
Nah guys script crud itu ada beberapa nanti ada index.php ada koneksi . ada tambah. ada edit . ada delete dan juga tentunya itu ada aksinya semua
yuk langsung
Pertama Buat Script Index.php
<html>
<head>
<title>Belajar PHP CRUD</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<body bgcolor="#800000">
<font face="tohama" color="cyan"><h1 align="center">DATA SISWA LOMBA KOMPETENSI SISWA</font></p></h1>
<a href="tambah.php"><p align="center"><img src="input.png" align="center"></a></p>
<!-- <a href="tambah.php">+ TAMBAH MAHASISWA</a> -->
<table class="tbl-qa" align="center">
<thead>
<tr>
<th class="table_header" wnimmhsth="20%" align="center">NO</th>
<th class="table_header" wnimmhsth="20%" align="center">Nama</th>
<th class="table_header" wnimmhsth="20%" align="center">NIS</th>
<th class="table_header" wnimmhsth="20%" align="center">Alamat</th>
<th class="table_header" wnimmhsth="20%" align="center">Jurusan</th>
<th class="table_header" wnimmhsth="20%" colspan="2" align="center">Aksi</th>
</tr>
</thead>
<?php
include "koneksi1.php";
$no = 1;
$data = mysqli_query ($con,"select * from 1_siswa");
while ($d = mysqli_fetch_array ($data)){
?>
<tr class="table-row">
<td class="table-row"><?php echo $no++; ?></td>
<td class="table-row"><?php echo $d['nama'];
?></td>
<td class="table-row"><?php echo $d['nis'];
?></td>
<td class="table-row"><?php echo $d['Alamat'];
?></td>
<td class="table-row"><?php echo $d['jurusan'];
?></td>
<td class="table-row">
<a href="edit.php?id=<?php echo $d['id'];
?>"><img src="oyi.png"></a></td>
<td class="table-row">
<a href="hapus.php?id=<?php echo $d['id']; ?>"
onClick="return confrim ('Apakah Anda yakin Ingin Menghapus Data?')"/><img src="delet.png">
</a></td>
<!-- <a href="hapus.php?id=<?php echo $d['id'];?>">HAPUS</a> -->
</td>
</tr>
<?php
}
?>
</table>
<p align="center"><font size="3" face="Bodoni MT" color="white">©Abdulloh Aqil 2018</p></font>
</body>
</html>
Script Ke dua untuk Koneksi database ke php Koneksi 1.php
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "db_akademik";
$con = mysqli_connect($host,$user,$pass); mysqli_select_db($con, $db);
// Cek koneksi
if (mysqli_connect_error()){
echo "Koneksi database gagal : " . mysqli_connect_error();
}
?>
Script Ke tiga yakni Untuk fitur pertama Tambah.php dan tambah aksi php
Tambah .php
<!DOCTYPE html>
<html>
<head>
<title>TAMBAH DATA SISWA TKJ</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="css_siswa.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h2 align="center">TAMBAH DATA SISWA<DATA1></DATA1></h2>
<br/>
<nav>
<a href="index.php">HOME</a>
<a href="tambah.php">TAMBAH DATA</a>
<a href="index.php">KEMBALI</a>
</nav>
<!-- <div class="button_link"></div> -->
<br/>
<form method="post" action="tambah_aksi.php">
<table class="tbl-qa">
<tr>
<td>Nama</td>
<td><input type="text" name="nama"></td>
</tr>
<tr>
<td>NIS</td>
<td><input type="number" name="nis"></td>
</tr>
<tr>
<td>Alamat</td>
<td><input type="text" name="alamat"></td>
</tr>
<tr>
<td>jurusan</td>
<td><input type="text" name="jurusan" placeholder="TKJ.AKA.KA.KI.APK.MM.RPL.PM -> Ada 8 JURUSAN SILAHKAN PILIH"></td>
</tr>
<tr>
<td>AKSI</td>
<td><input type="submit" value="SIMPAN">
</td>
</tr>
</table>
</form>
</body>
</html>
Tambah_aksi.php
<?php
//koneksi database
include 'koneksi1.php';
//menangkap data yang dikirim dari form
$nama = $_POST['nama'];
$nis = $_POST['nis'];
$alamat =$_POST['alamat'];
$jurusan = $_POST['jurusan'];
//CEK DATA KOSONG
if (!empty($nama) && !empty($nis) && !empty($alamat) && !empty($jurusan)){
//Menginput data ke database
mysqli_query($con,"insert into 1_siswa values('','$nama','$nis','$alamat','$jurusan')");
echo "<script type='text/javascript'>alert('Data Berhasil Disimpan');window.location.href='index.php';</script>";
}else {
echo "<script type='text/javascript'>alert('Data Masih ada yang kosong');window.location.href='tambah.php';</script>";
}
?>
Scrip keempat untuk fitur ke 2 nya yakni mengedit data . edit.php dan edit_aksi.php
Edit.php
<!DOCTYPE html>
<html>
<head>
<title>EDIT DATA SISWA</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="css_siswa.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h2 align="center">EDIT DATA SISWA <DATA1></DATA1></h2>
<br/>
<br/>
<?php
include 'koneksi1.php';
$id = $_GET['id'];
$data = mysqli_query ($con, "select * from 1_siswa where id='$id'");
while ($d = mysqli_fetch_array($data)){
?>
<form method="post" action="edit_aksi.php">
<table >
<tr>
<td>Nama</td>
<td>
<input type="hidden" name="id" value="<?php echo $d['id']; ?>">
<input type="text" name="nama" value="<?php echo $d['nama']; ?>">
</td>
</tr>
<tr>
<td>NIS</td>
<td><input type="number" name="nis" value="<?php echo $d['nis']; ?>">
</td>
</tr>
<tr>
<td>Alamat</td>
<td><input type="text" name="alamat" value="<?php echo $d['Alamat']; ?>">
</td>
</tr>
<tr>
<td>Jurusan</td>
<td><input type="text" name="jurusan" value="<?php echo $d['jurusan']; ?>">
</td>
</tr>
<tr>
<td>AKSI</td>
<td><input type="submit" value="SIMPAN"></td>
</tr>
<tr>
<td>ATAU</td>
<td><a href="index.php"><input type="button" value="KEMBALI KE HALAMAN UTAMA" align="center"></a></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
Edit_aksi.php
<?php
//koneksi database
include 'koneksi1.php';
//menangkap data yang dikirim dari form
$id = $_POST['id'];
$nama = $_POST['nama'];
$nis = $_POST['nis'];
$alamat = $_POST['alamat'];
$jurusan = $_POST['jurusan'];
//update data ke database
mysqli_query($con,"update 1_siswa set nama='$nama', nis='$nis',alamat='$alamat',
jurusan='$jurusan'where id='$id'");
echo "<script type='text/javascript'>alert('Data Berhasil Diedit');window.location.href='index.php';</script>";
?>
Untuk Scrip fitur ke 3 menghapus data . cuku hapus.php
Hapus.php
<?php
//koneksi database
include 'koneksi1.php';
//menangkap data id yang dikiirim dari url
$id = $_GET['id'];
//Menghapus data dari database
mysqli_query($con, "delete from 1_siswa where id='$id'");
echo "<script type='text/javascript'>alert('Data Berhasil Dihapus');window.location.href='index.php';</script>";
?>
ada script cssnya
style.css
tbl-qa{width: 50%;font-size:0.9em;background-color: #6ab5b9;border-spacing:
1px;border-radius: 4px;}
.tbl-qa.table-header th {padding:5px;text-align:left;padding:10px;background-color:#E6E6FA;font-weight:normal;}
.tbl-qa .table-row td {padding:10px;background-color: #ADFF2F;vertical-align:top;}
.button_link {padding: 20px 0px;}
.button_link a{color: #000000;text-decoration: none;background-color:
#7FFFD4;padding: 8px 20px;font-size: 0.8em;border: #428a8e 1px solid; border-radius: 4px;}
.message { color: #FF0000;
text-align: center; width: 100%;
}
.txtField {padding: 8px;border: #afced0 1px solid;border-radius: 4px;width: 250px;}
.demo-form-submit {color: #FFF;background-color: #4e7173;padding: 10px
50px;border: 0px;cursor: pointer;border-radius:4px;}
.message { padding:8px 10px;box-sizing: border-box;text-align: left;border-radius: 4px;}
.success {background-color: #c4e4c4;border: #9ac19a 1px solid;color: #4b8e4b;}
.error {background-color: #e4cbc4;border: #c19c9a 1px solid;color: #8e4e4b;}
css_siswa.css
table, th, td {
border: 1px solid black; border-collapse: collapse;
}
th, td {
padding: 5px; text-align: left;
}
input[type=text], select { width: 100%;
padding: 12px 20px; margin: 8px 0; display: inline-block; border: 1px solid #ccc; border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] { width: 100%;
background-color: #4CAF50; color: white;
padding: 14px 20px;
margin: 8px 0; border: none; border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover { background-color: #45a049;
}
div {
border-radius: 5px; background-color: #f2f2f2; padding: 20px;
}
section { width: 80%;
padding: 20px; margin: 20px auto;
background-color: white;
}
h1 {
color: #F30;
font-size: 36px;
}
nav{
background-color: #4CAF50; color: #fff;
height: 60px; margin: 10px 0;
}
nav a{ float: left;
padding: 20px; height: 20px;
text-decoration: none; color: #FFF;
}
nav a:hover {
background-color: #1f663a;
}
article {
min-height: 20px; color: #333;
}
footer {
text-align: center; display: block; margin-button: 10px;
}
Oke guys cuma itu scripnya
Note : Karena admin menggunaka sebuah icon untuk mengaplikasakan fitur di crud tersebut maka download dulu icon dibawah ini
Untuk delet.php
untuk tambah.php
untuk edit.php
Selamat Mencoba . Good Luck :)
Komentar
Posting Komentar