Web Development
215

Simple CRUD di PHP dengan studi kasus ! ! !






  29-Oct-2020 17:18:33



Latihan Praktikum 5

Kerjakan latihan-latihan modul Praktikum 5 (halaman 12) pada localhost masing-masing. File yang perlu dikumpulkan:

  1. File welcome.php, login.php, login_action.php
  2. Screenshoot tampilan browser untuk file login.php

penyelesaian

1. Buatlah database tersetah anda 

2. Copy sql berikut, save dengan .sql 

3. Buatlah file koneksi.php 

<?php

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

?>

4. Buatlah form loginya, dan actionya 
semisal form login php, dan formact.php. disini saya memakai metod POST, kenapa ? karena kalau GET jadi di url akan ditampilkan parameternya 
Source form.php 
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <style>
            body{
                font-family: sans-serif;
                background-color: skyblue;
            }

            h1{
                text-align: center;
                /*ketebalan font*/
                font-weight: 300;
            }

            .tulisan_login{
                text-align: center;
                /*membuat semua huruf menjadi kapital*/
                text-transform: uppercase;
            }

            .kotak_login{
                width: 450px;
                background: white;
                /*meletakkan form ke tengah*/
                margin: 70px auto;
                padding: 30px 25px;
            }

            label{
                font-size: 11pt;
            }

            .form_login{
                /*membuat lebar form penuh*/
                box-sizing : border-box;
                width: 100%;
                padding: 10px;
                font-size: 11pt;
                margin-bottom: 20px;
            }

            .tombol_login{
                background: blue;
                color: white;
                font-size: 11pt;
                width: 100%;
                border: none;
                border-radius: 3px;
                padding: 10px 20px;
            }
    </style>
    <meta charset="utf-8">
    <title>Login dulu</title>
  </head>
  <body>
    <div class="kotak_login">
       <p class="tulisan_login"><h1>Admin amikom news</h1>
    <form action="loginact.php" method="post">
      Username : <input type="text" class="form_login" name="user" />
      <br />
      Password : <input type="password" class="form_login" name="password" />
      <br />
      <input type="submit" class="tombol_login" value="Login" />
  </body>
</div>
</html>

Loginact.php 
<?php
include 'koneksi.php';

$username = htmlspecialchars($_POST['user']);
$password = htmlspecialchars($_POST['password'])

$login = mysqli_query($koneksi,"SELECT * FROM user WHERE user_nama='$username' AND user_password='$password'");
$cek   = mysqli_num_rows($login)

if($cek > 0)
{
session_start();
  $data = mysqli_fetch_assoc($login);

$_SESSION['username'] = $username;
$_SESSION['status'] = "login";
header("Location:welcome.php");
exit();
}
else
{
header("Location:login.php");
}

?>

Setelah itu kalian run, hasil output 

Welcome.php 
<?php
session_start();
if(isset($_SESSION['username'])){ ?>
<h2>Control Panel</h2>
<p>Selamat datang "<?php echo $_SESSION['username']; ?>".
Klik <a href="logut.php">disini</a> untuk logout.</p>
<?php
} else { ?>
<h2>Maaf..</h2>
<p>Anda tidak berhak mengakses halaman ini.
Silakan <a href="login.php">login</a> terlebih dahulu. klik <a href="logut.php">keluar</p>
<?php
}

?>


DISCUSSION



29-Oct-2020 17:22:58

Dump sqlnya

sorry lupa

-- phpMyAdmin SQL Dump
-- version 4.9.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Oct 29, 2020 at 10:32 AM
-- Server version: 10.4.10-MariaDB
-- PHP Version: 7.3.12

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: `data1286`
--

-- --------------------------------------------------------

--
-- Table structure for table `berita`
--

CREATE TABLE `berita` (
`berita_id` int(11) NOT NULL,
`berita_judul` varchar(150) NOT NULL,
`berita_isi` text NOT NULL,
`berita_gambar` varchar(25) NOT NULL,
`berita_tanggal` date NOT NULL,
`user_nama` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- --------------------------------------------------------

--
-- Table structure for table `user`
--

CREATE TABLE `user` (
`user_nama` varchar(50) NOT NULL,
`user_password` varchar(50) NOT NULL,
`user_namalengkap` varchar(50) NOT NULL,
`user_email` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Dumping data for table `user`
--

INSERT INTO `user` (`user_nama`, `user_password`, `user_namalengkap`, `user_email`) VALUES
('bayu aji', 'bayu123', 'wahyu bayu aji', 'wahyu.1286@students.amikom.ac.id');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `berita`
--
ALTER TABLE `berita`
ADD PRIMARY KEY (`berita_id`),
ADD KEY `berita_id` (`berita_id`),
ADD KEY `user_nama` (`user_nama`);

--
-- Indexes for table `user`
--
ALTER TABLE `user`
ADD PRIMARY KEY (`user_nama`),
ADD KEY `user_nama` (`user_nama`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `berita`
--
ALTER TABLE `berita`
MODIFY `berita_id` int(11) NOT NULL AUTO_INCREMENT;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `berita`
--
ALTER TABLE `berita`
ADD CONSTRAINT `berita_ibfk_1` FOREIGN KEY (`user_nama`) REFERENCES `user` (`user_nama`);
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 */;




Reply

Login for comment and discussion.
Login Here
POST NEW DISCUSSION
Popular Posts
Gps Tracker Seccodeid Free Too...
Bayu aji Bayu aji
General
1442
118
Top

Mass Reverse IP Unlimited
ImamSy ImamSy
Hacking
1133
10
Top

Free Proxy List
Sandidi Sandidi
Networking
1127
3
Top

Report McAfee Antivirus Hurrri...
Indrasp Indrasp
Windows
829
93
Top

GHunt OSINT Tools - Investiga...
Sandidi Sandidi
Tools Hacking
723
3
Top

Related Post
Subscribe

Subscribe free now for latest posts