pertama buat dulu database nya dengan nama contoh dan tabel nya dengan nama admin. didalam tabel admin isi field nya username dan password
buat dulu file connect.php isi dengan script dibawah:
lalu buat file dengan nama proseslogin.php isi dengan script dibawah:
lalu buat file yang bernama index.php isi dengan script dibawah ini:
setelah itu buat file home.php dengan script:
buat dulu file connect.php isi dengan script dibawah:
<?php $host = "localhost"; $user = "root"; $pass = ""; $db = "contoh"; $konek = mysql_connect($host, $user, $pass) or die ('Koneksi Gagal!'); mysql_select_db($db); ?> |
lalu buat file dengan nama proseslogin.php isi dengan script dibawah:
<?php session_start(); require_once("connect.php"); $user = $_POST['username']; $pass = $_POST['password']; $cekuser = mysql_query("SELECT * FROM admin WHERE username='$user' and password='$pass'"); $jumlah = mysql_num_rows($cekuser); $hasil = mysql_fetch_array($cekuser); if($jumlah == 0) { echo " Username & Password Salah!<br/>"; } else { $_SESSION['username'] = "$user"; header('location:home.php'); } ?> |
lalu buat file yang bernama index.php isi dengan script dibawah ini:
<table border="0" align="center"> <form action="proseslogin.php" method="post"> <tr> <td>Username</td> <td>:</td> <td><input size="40" type="text" name="username" /></td> </tr> <tr> <td>Password</td> <td>:</td> <td><input size="40" type="password" name="password"/></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" value="Login" /></td> </tr> </table> </form> |
setelah itu buat file home.php dengan script:
<h1>BERHASIL</h1> |




