Commit 88a59235 by Febiola Simangunsong

Crud_akun_dosen

parents
# Simple-CRUD-PHP-MySQLi
<!-- <img width="200" src="https://static.cdn-cdpl.com/700x350/998b78e349061b4971c0a2b0e8d6be41/php_logo-image700x350-crop-image700x350-crop-image(700x350-crop)-image(700x350-crop).png">
&nbsp;
<img width="200" src="https://i1.wp.com/www.elearningworld.org/wp-content/uploads/2019/04/MySQL.svg.png?fit=600%2C400&ssl=1"> -->
<p align="center">
<a href="https://www.php.net/">
<img
alt="PHP"
src="https://static.cdn-cdpl.com/700x350/998b78e349061b4971c0a2b0e8d6be41/php_logo-image700x350-crop-image700x350-crop-image(700x350-crop)-image(700x350-crop).png"
width="200"
/>
<img
alt="MySQL"
src="https://i1.wp.com/www.elearningworld.org/wp-content/uploads/2019/04/MySQL.svg.png?fit=600%2C400&ssl=1"
width="200"
/>
</a>
</p>
<!-- ![Untitled](https://static.cdn-cdpl.com/700x350/998b78e349061b4971c0a2b0e8d6be41/php_logo-image700x350-crop-image700x350-crop-image(700x350-crop)-image(700x350-crop).png) -->
<!-- ![Untitled](https://i1.wp.com/www.elearningworld.org/wp-content/uploads/2019/04/MySQL.svg.png?fit=600%2C400&ssl=1) -->
## Table Of Contents
- [Table Of Content](#table-of-content)
- [Features](#features)
- [Build Setup](#build-setup)
- [Installation](#installation)
- [Stacks](#stacks)
- [Environment Recomended](#environment-recomended)
## Features
1. Input Data
2. Delete Data
3. Update Data
4. Display Data
## Build Setup
- Clone Repository `https://github.com/arul29/Simple-CRUD-PHP-MySQLi.git`
- Import database `crud_simple.sql` to phpMyAdmin
## Installation
- Upload/move data to your php server
- Open your server url, example: `http://localhost/simplecrudphp`
## Stacks
HTML, PHP & MySQLi.
## Environment Recomended
- Webserver Apache
- PHP 7.x
- MySQL / MariaDB
---
Copyright © 2019 by Andi Mashdarul Khair
<a href="index.php">Show Data</a>
<br><br>
<form method="post">
<table>
<tr>
<td>NIDN</td>
<td><input type="text" name="nidn" placeholder="Masukkan NIDN" required></td>
</tr>
<tr>
<td>Nama</td>
<td><input type="text" name="nama" placeholder="Masukkan Nama" required></td>
</tr>
<tr>
<td>Jabatan</td>
<td><input type="text" name="jabatan" placeholder="Masukkan Jabatan" required></td>
</tr>
<tr>
<td>Program Studi</td>
<td>
<select name="program_studi" >
<option value="D3 Teknologi Informasi">D3 Teknologi Informasi</option>
<option value="D3 Teknologi Komputer">D3 Teknologi Komputer</option>
<option value="D4 Teknologi Rekayasa Perangkat Lunak">D4 Teknologi Rekayasa Perangkat Lunak</option>
<option value="S1 Informatika">S1 Informatika</option>
<option value="S1 Sistem Informasi">S1 Sistem Informasi</option>
<option value="S1 Teknik Elektro">S1 Teknik Elektro</option>
</select>
</td>
</tr>
<tr>
<td>Golongan</td>
<td><input type="text" name="golongan" placeholder="Masukkan golongan" required></td>
</tr>
<tr>
<td>Pendidikan</td>
<td><input type="text" name="pendidikan" placeholder="Masukkan Pendidikan" required></td>
</tr>
<tr>
<td>Tahun Mulai S1</td>
<td><input type="date" name="mulai_s1"></td>
</tr>
<tr>
<td>Tahun Lulus S1</td>
<td><input type="date" name="lulus_s1"></td>
</tr>
<tr>
<td>Tahun Mulai S2</td>
<td><input type="date" name="mulai_s2"></td>
</tr>
<tr>
<td>Tahun Lulus S2</td>
<td><input type="date" name="lulus_s2"></td>
</tr>
<tr>
<td>Username</td>
<td><input type="username" name="username" placeholder="Masukkan Username" required></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" placeholder="Masukkan Password" required></td>
</tr>
<tr>
<td>Email</td>
<td><input type="email" name="email" placeholder="Masukkan email" required></td>
</tr>
<tr>
<td><input type="submit" name="add" value="Add"></td>
<td><input type="reset" name="reset" value="Cancel"></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['add']))
{
include 'config.php';
$nidn = $_POST['nidn'];
$nama = $_POST['nama'];
$jabatan = $_POST['jabatan'];
$program_studi = $_POST['program_studi'];
$golongan = $_POST['golongan'];
$pendidikan = $_POST['pendidikan'];
$mulai_s1 = $_POST['mulai_s1'];
$lulus_s1 = $_POST['lulus_s1'];
$mulai_s2 = $_POST['mulai_s2'];
$lulus_s2 = $_POST['lulus_s2'];
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$sql="INSERT INTO dosen (nidn, nama, jabatan, program_studi, golongan, pendidikan, mulai_s1, lulus_s1, mulai_s2, lulus_s2, username, password, email) VALUES ('$nidn','$nama','$jabatan','$program_studi','$golongan', '$pendidikan', '$mulai_s1', '$lulus_s1', '$mulai_s2', '$lulus_s2', '$username', '$password', '$email')";
if($conn->query($sql) === false)
{
trigger_error('Wrong SQL Command: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
}
else
{
echo "<script>alert('Add Success!')</script>";
echo "<meta http-equiv=refresh content=\"0; url=index.php\">";
}
}
?>
\ No newline at end of file
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'pa2';
$conn = new mysqli($dbhost,$dbuser,$dbpass,$dbname);
if($conn->connect_error)
{
die('Failed Connect ! '.$conn->connect_error);
}
?>
\ No newline at end of file
-- phpMyAdmin SQL Dump
-- version 4.7.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jan 06, 2020 at 06:51 PM
-- Server version: 10.1.26-MariaDB
-- PHP Version: 7.1.9
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `crud_simple`
--
-- --------------------------------------------------------
--
-- Table structure for table `college_student`
--
CREATE TABLE `college_student` (
`student_id` varchar(10) NOT NULL,
`name` varchar(50) NOT NULL,
`majors` varchar(40) NOT NULL,
`gender` varchar(12) NOT NULL,
`address` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `college_student`
--
INSERT INTO `college_student` (`student_id`, `name`, `majors`, `gender`, `address`) VALUES
('1111', 'Kenzo', 'Civil', 'Male', 'Yogyakarta'),
('2222', 'Iyan', 'Architect', 'Male', 'Yogyakarta'),
('3333', 'Andi', 'Informatics', 'Male', 'Yogyakarta');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `college_student`
--
ALTER TABLE `college_student`
ADD PRIMARY KEY (`student_id`);
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
<a href="add.php">Add</a>
<br><br>
<table border="">
<tbody>
<tr>
<th>NIDN</th>
<th>Nama</th>
<th>Jabatan</th>
<th>Program Studi</th>
<th>Golongan</th>
<th>Pendidikan</th>
<th>Tahun Mulai S1</th>
<th>Tahun Lulus S1</th>
<th>Tahun Mulai S2</th>
<th>Tahun Lulus S2</th>
<th>Username</th>
<th>Password</th>
<th>Email</th>
</tr>
<?php
include 'config.php';
$a=mysqli_query($conn,"SELECT * FROM dosen");
foreach ($a as $b)
{
?>
<tr>
<td><?= $b['nidn']; ?></td>
<td><?= $b['nama']; ?></td>
<td><?= $b['jabatan']; ?></td>
<td><?= $b['program_studi']; ?></td>
<td><?= $b['golongan']; ?></td>
<td><?= $b['pendidikan']; ?></td>
<td><?= $b['mulai_s1']; ?></td>
<td><?= $b['lulus_s1']; ?></td>
<td><?= $b['mulai_s2']; ?></td>
<td><?= $b['lulus_s2']; ?></td>
<td><?= $b['username']; ?></td>
<td><?= $b['password']; ?></td>
<td><?= $b['email']; ?></td>
<td>
<a href="update.php?nidn=<?= $b['nidn']; ?>"><b><i>Edit</i></b></a> |
<a href="index.php?nidn=<?= $b['nidn']; ?>" onclick="return confirm('Are you sure?')"><b><i>Delete</i></b></a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
if(isset($_GET['nidn']))
{
$nidn=$_GET['nidn'];
$sql="DELETE FROM dosen WHERE nidn='$nidn'";
if($conn->query($sql) === false)
{ // Jika gagal meng-insert data tampilkan pesan dibawah 'Perintah SQL Salah'
trigger_error('Wrong SQL Command: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
}
else
{ // Jika berhasil alihkan ke halaman tampil.php
echo "<script>alert('Delete Success!')</script>";
echo "<meta http-equiv=refresh content=\"0; url=index.php\">";
}
}
?>
\ No newline at end of file
<a href="index.php">Show Data</a>
<br><br>
<?php
include 'config.php';
$a=mysqli_query($conn,"SELECT * FROM dosen WHERE nidn='$_GET[nidn]'");
$b=mysqli_fetch_array($a,MYSQLI_ASSOC)
?>
<form method="post">
<table>
<tr>
<td>NIDN</td>
<td><input type="text" name="nidn" placeholder="Masukkan NIDN" value="<?= $b['nidn'] ?>"></td>
</tr>
<tr>
<td>Nama</td>
<td><input type="text" name="nama" placeholder="Masukkan Nama" value="<?= $b['nama']; ?>"></td>
</tr>
<tr>
<td>Jabatan</td>
<td><input type="text" name="jabatan" placeholder="Masukkan Jabatan" value="<?= $b['jabatan']; ?>"></td>
</tr>
<tr>
<td>Program Studi</td>
<td>
<select name="program_studi" >
<option value="D3 Teknologi Informasi" <?php if($b['program_studi'] == "D3 Teknologi Informasi") echo "selected"; ?>>D3 Teknologi Informasi</option>
<option value="D3 Teknologi Komputer" <?php if($b['program_studi'] == "D3 Teknologi Komputer") echo "selected"; ?>>D3 Teknologi Komputer</option>
<option value="D4 Teknologi Rekayasa Perangkat Lunak" <?php if($b['program_studi'] == "D4 Teknologi Rekayasa Perangkat Lunak") echo "selected"; ?>>D4 Teknologi Rekayasa Perangkat Lunak</option>
<option value="S1 Informatika"<?php if($b['program_studi'] == "S1 Informatika") echo "selected"; ?>>S1 Informatika</option>
<option value="S1 Sistem Informasi" <?php if($b['program_studi'] == "S1 Sistem Informasi") echo "selected"; ?>>S1 Sistem Informasi</option>
<option value="S1 Teknik Elektro" <?php if($b['program_studi'] == "S1 Teknik Elektro") echo "selected"; ?>>S1 Teknik Elektro</option>
</select>
</td>
</tr>
<tr>
<td>Golongan</td>
<td><input type="text" name="golongan" placeholder="Masukkan golongan" value="<?= $b['golongan']; ?>"></td>
</tr>
<tr>
<td>Pendidikan</td>
<td><input type="text" name="pendidikan" placeholder="Masukkan Pendidikan" value="<?= $b['pendidikan']; ?>"></td>
</tr>
<tr>
<td>Tahun Mulai S1</td>
<td><input type="date" name="mulai_s1" value="<?= $b['mulai_s1']; ?>"></td>
</tr>
<tr>
<td>Tahun Lulus S1</td>
<td><input type="date" name="lulus_s1" value="<?= $b['lulus_s1']; ?>"></td>
</tr>
<tr>
<td>Tahun Mulai S2</td>
<td><input type="date" name="mulai_s2" value="<?= $b['mulai_s2']; ?>"></td>
</tr>
<tr>
<td>Tahun Lulus S2</td>
<td><input type="date" name="lulus_s2" value="<?= $b['lulus_s2']; ?>"></td>
</tr>
<tr>
<td>Username</td>
<td><input type="username" name="username" placeholder="Masukkan Username" value="<?= $b['username']; ?>"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" placeholder="Masukkan Password" value="<?= $b['password']; ?>"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="email" name="email" placeholder="Masukkan email" value="<?= $b['email']; ?>"></td>
</tr>
<tr>
<td><input type="submit" name="update" value="Update"></td>
<td><input type="reset" name="reset" value="Cancel"></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['update']))
{
include 'config.php';
$nidn = $_POST['nidn'];
$nama = $_POST['nama'];
$jabatan = $_POST['jabatan'];
$program_studi = $_POST['program_studi'];
$golongan = $_POST['golongan'];
$pendidikan = $_POST['pendidikan'];
$mulai_s1 = $_POST['mulai_s1'];
$lulus_s1 = $_POST['lulus_s1'];
$mulai_s2 = $_POST['mulai_s2'];
$lulus_s2 = $_POST['lulus_s2'];
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$sql="UPDATE dosen SET nidn='$nidn', nama='$nama', jabatan='$jabatan', program_studi='$program_studi', golongan='$golongan', pendidikan='$pendidikan', mulai_s1='$mulai_s1', lulus_s1='$lulus_s1', mulai_s2='$mulai_s2', lulus_s2='$lulus_s2', username='$username', password='$password', email='$email' WHERE nidn='$_GET[nidn]'";
if($conn->query($sql) === false)
{ // Jika gagal meng-insert data tampilkan pesan dibawah 'Perintah SQL Salah'
trigger_error('Wrong SQL Command: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
}
else
{ // Jika berhasil alihkan ke halaman tampil.php
echo "<script>alert('Update Success!')</script>";
echo "<meta http-equiv=refresh content=\"0; url=index.php\">";
}
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment