Skip to content

Commit c3daa9c

Browse files
committed
aa
0 parents  commit c3daa9c

8 files changed

+219
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# php-u
2+
3+
latihan php crud

form-update.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<?php
11+
//var_dump($_GET['id']);
12+
$id=$_GET['id'];
13+
?>
14+
<form action="proses-update.php" method="post">
15+
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
16+
<input type="text" placeholder="nama" name="nama">
17+
<input type="text" placeholder="email" name="email">
18+
<input type="text" placeholder="password" name="password">
19+
<button type="submit">Submit</button>
20+
</form>
21+
22+
</body>
23+
</html>

index.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
11+
<?php
12+
include('koneksi.php');
13+
14+
///READ
15+
$sql="SELECT * FROM user";
16+
$query=mysqli_query($conn,$sql);
17+
while($row=mysqli_fetch_array($query)){
18+
echo $row['id']." | ";
19+
echo $row['nama']." | ";
20+
echo $row['email']." | ";
21+
//aslinya gini
22+
///<a href="proses-delete.php?id=5" >Delete</a>
23+
24+
//kalo di buat dinamis jadi gini...
25+
echo "<a href='proses-delete.php?id=".$row['id']." '>Delete</a>";
26+
echo "<a href='form-update.php?id=".$row['id']." '>Update</a>";
27+
echo "<br>";
28+
}
29+
30+
/*
31+
INSERT INTO table_name (column1, column2, column3, ...)
32+
VALUES (value1, value2, value3, ...);
33+
34+
*/
35+
?>
36+
<form action="proses-create.php" method="post">
37+
<input type="text" placeholder="nama" name="nama">
38+
<input type="text" placeholder="email" name="email">
39+
<input type="text" placeholder="password" name="password">
40+
<button type="submit">Submit</button>
41+
</form>
42+
43+
</body>
44+
</html>

koneksi.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
$username="root";
3+
$password="";
4+
$server="localhost";
5+
$namadatabase="latihan_db";
6+
$conn=mysqli_connect($server,$username,$password,$namadatabase);
7+
8+
if(!$conn){
9+
echo "gagal konek !!";
10+
die();
11+
}
12+
13+
14+
?>

proses-create.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
include('koneksi.php');
3+
4+
$nama=$_POST['nama'];
5+
$email=$_POST['email'];
6+
$pass=$_POST['password'];
7+
8+
//CREATE
9+
$sql="INSERT INTO user (nama,email,password) VALUES ('$nama','$email','$pass') ";
10+
$query= mysqli_query($conn,$sql);
11+
if($query){
12+
echo "Berhasil di simpan";
13+
header('location:index.php');
14+
}
15+
else{
16+
echo "gagal";
17+
}
18+
19+
20+
?>

proses-delete.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
include('koneksi.php');
3+
4+
$id=$_GET['id'];
5+
6+
$sql="DELETE FROM user WHERE id='$id' ";
7+
$query=mysqli_query($conn,$sql);
8+
if($query){
9+
echo "berhasil di delete";
10+
header('location:index.php');
11+
}
12+
else{
13+
echo "gagal";
14+
}
15+
16+
17+
18+
?>

proses-update.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
include('koneksi.php');
3+
4+
$id=$_POST['id'];
5+
$nm=$_POST['nama'];
6+
$email=$_POST['email'];
7+
$pass=$_POST['password'];
8+
9+
// var_dump($id);
10+
// var_dump($nm);
11+
// var_dump($email);
12+
// var_dump($pass);
13+
14+
/*
15+
UPDATE table_name
16+
SET column1 = value1, column2 = value2, ...
17+
WHERE condition;
18+
*/
19+
$sql="UPDATE user SET nama='$nm', email ='$email', password='$pass' WHERE id ='$id' ";
20+
$query=mysqli_query($conn,$sql);
21+
if($query){
22+
echo "berhasil";
23+
header('location:index.php');
24+
}
25+
else{
26+
echo "GAGAL";
27+
}
28+
29+
30+
31+
?>

user.sql

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
-- phpMyAdmin SQL Dump
2+
-- version 4.6.6deb5
3+
-- https://www.phpmyadmin.net/
4+
--
5+
-- Host: localhost:3306
6+
-- Generation Time: Mar 12, 2019 at 04:42 PM
7+
-- Server version: 5.7.25-0ubuntu0.18.04.2
8+
-- PHP Version: 7.2.15-0ubuntu0.18.04.1
9+
10+
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
11+
SET time_zone = "+00:00";
12+
13+
14+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
15+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
16+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
17+
/*!40101 SET NAMES utf8mb4 */;
18+
19+
--
20+
-- Database: `latihan_db`
21+
--
22+
23+
-- --------------------------------------------------------
24+
25+
--
26+
-- Table structure for table `user`
27+
--
28+
29+
CREATE TABLE `user` (
30+
`id` int(11) NOT NULL,
31+
`nama` varchar(100) NOT NULL,
32+
`email` varchar(100) NOT NULL,
33+
`password` varchar(100) NOT NULL
34+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
35+
36+
--
37+
-- Dumping data for table `user`
38+
--
39+
40+
INSERT INTO `user` (`id`, `nama`, `email`, `password`) VALUES
41+
(1, 'AL BIRR KARIM SUSANTO', 'albirkarim1@gmail.com', 'asdfghjkl'),
42+
(2, 'De rosal', 'leo99@gg.com', 'asdfghjkl'),
43+
(4, 'Leonardus', 'leo99@gg.comaaaaaaa', 'asdfghjkl');
44+
45+
--
46+
-- Indexes for dumped tables
47+
--
48+
49+
--
50+
-- Indexes for table `user`
51+
--
52+
ALTER TABLE `user`
53+
ADD PRIMARY KEY (`id`);
54+
55+
--
56+
-- AUTO_INCREMENT for dumped tables
57+
--
58+
59+
--
60+
-- AUTO_INCREMENT for table `user`
61+
--
62+
ALTER TABLE `user`
63+
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
64+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
65+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
66+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

0 commit comments

Comments
 (0)