Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

PHP dan MySQL (Studikasus: Login) Jumadi, S.T. Blog: jumadi.blog.ugm.ac.id Email: mcs.jumadi@mail.ugm.ac.id.

Presentasi serupa


Presentasi berjudul: "PHP dan MySQL (Studikasus: Login) Jumadi, S.T. Blog: jumadi.blog.ugm.ac.id Email: mcs.jumadi@mail.ugm.ac.id."— Transcript presentasi:

1 PHP dan MySQL (Studikasus: Login) Jumadi, S.T. Blog: jumadi.blog.ugm.ac.id

2 AppServ:Apache+PHP+Mysql

3

4 Membuat Database dan Tabel
CREATE DATABASE pengunjung; CREATE TABLE pengunjung.bukutamu (nama varchar(50), varchar(50),komentar varchar(160)); INSERT INTO pengunjung.bukutamu VALUES ('akas', 'Bandung mesti sukses'); INSERT INTO pengunjung.bukutamu VALUES ('ajum', 'Bandungku Bandungmu'); INSERT INTO pengunjung.bukutamu VALUES ('keukeu', 'Bandung berbunga'); INSERT INTO pengunjung.bukutamu VALUES ('rossa', 'Bandung is the best');

5 Query pada MySQL Server

6 AppServ: Document Root

7 Form Input Data nama file: input.php
<html> <body> <form name="fdata" action="http://localhost/folder/simpan.php" method="post"> <table border=“0"> <tr><td>Nama</td><td><input type="text" name="nama"></td></tr> <tr><td> </td><td><input type="text" name=" "></td></tr> <tr><td>Komentar</td><td><input type="text" name="komentar"></td></tr> <tr><td></td><td><input type="submit" name="btkirim" value="Kirim"></td></tr> </table> </form> </body> </html>

8 Tampilan Form Input Data file: input.php

9 Menyimpan Database nama file: simpan.php
<html> <body> <? $conn=mysql_connect("localhost","root","123"); if ($conn){ mysql_select_db("pengunjung"); echo "Nama=$nama<br>"; echo " =$ <br>"; echo "Komentar=$komentar<br>"; $perintah="insert into bukutamu (nama, ,komentar) values ('$nama','$ ','$komentar')"; $hasil=mysql_query($perintah,$conn); if ($hasil){ echo "<br><br>Data telah tersimpan"; } mysql_close($conn); }else{ echo "Gagal Koneksi ke server"; ?> <br><br> <a href="http://localhost/FOLDER/input.php">Input Data</a> <br> <a href="http://localhost/FOLDER/tampil.php">Tampil Data</a> </body> </html>

10 Menyimpan Database file: simpan.php

11 Menampilkan isi database nama file: tampil.php
<html> <body> <? $conn=mysql_connect("localhost","root","123"); if ($conn){ mysql_select_db("pengunjung"); $perintah="select * from bukutamu"; $hasil=mysql_query($perintah,$conn); $baris=mysql_fetch_row($hasil); if ($baris){ echo "<table border='1'><tr><td>NAMA</td><td> </td><td>KOMENTAR</td></tr>"; do { list($nama,$ ,$komentar)=$baris; echo "<tr><td>$nama</td>"; echo "<td>$ </td>"; echo "<td>$komentar</td></tr>"; }while ($baris=mysql_fetch_row($hasil)); echo "</table>"; }else{ echo "Data tidak ada"; } mysql_close($conn); echo "Gagal Koneksi ke server"; ?> <br><br> <a href="http://localhost/FOLDER/input.php">Input Data</a> </body> </html>

12 Hasil penampilan isi database file: tampil.php

13 Form pencarian Data nama file: formcari.php
<html> <body> <form name="fcari" method="post" action="http://localhost/folder/cari.php"> <table border="0"> <tr><td>Masukan nama</td><td><input type="text" name="kunci"></td></tr> <tr><td></td><td><input type="submit" value="Cari"></td></tr> </table> </form> </body> </html>

14 Script pencarian Data nama file: cari.php
<? $conn=mysql_connect("localhost","root","123"); if ($conn){ mysql_select_db("pengunjung"); $perintah="select * from bukutamu where nama LIKE '%$kunci%'"; $hasil=mysql_query($perintah,$conn); $baris=mysql_fetch_row($hasil); if ($baris){ echo "<table border='1'><tr><td>NAMA</td><td> </td><td>KOMENTAR</td></tr>"; do { list($nama,$ ,$komentar)=$baris; echo "<tr><td>$nama</td>"; echo "<td>$ </td>"; echo "<td>$komentar</td></tr>"; }while ($baris=mysql_fetch_row($hasil)); echo "</table>"; }else{ echo "Data tidak ada"; } mysql_close($conn); echo "Gagal Koneksi ke server"; ?> <br><br> <a href="http://localhost/FOLDER/formcari.php">Cari Data</a> </body> </html>

15 Database pengguna

16 Form pencarian nama file: login.php
<html> <body> <form name="fdata" action="http://localhost/folder/cek.php" method="post"> <table border="0"> <tr><td>User name</td><td><input type="text" name="pengguna"></td></tr> <tr><td>Password</td><td><input type=“password" name="sandi"></td></tr> <tr><td></td><td><input type="submit" name="btlogin" value="Login"></td></tr> </table> </form> </body> </html>

17 Script cek login nama file: cek.php
<html> <body> <? $conn=mysql_connect("localhost","root","123"); if ($conn){ mysql_select_db("pengguna"); $perintah="select * from login where username='$pengguna'"; $hasil=mysql_query($perintah,$conn); $baris=mysql_fetch_row($hasil); if ($baris){ $cek=false; do { list($username,$password,$level)=$baris; if($password==$sandi){ $cek=true; $otoritas=$level; } }while ($baris=mysql_fetch_row($hasil)); if($cek){ echo "<h1>Selamat Datang</h1>"; switch ($otoritas){ case 1: echo "<br>Otoritas anda sebagai Administrator"; break; case 2: echo "<br>Otoritas anda sebagai Tamu"; break; } }else{ echo "Password anda salah!!!"; } }else{ echo "Username tidak terdaftar....";} mysql_close($conn); }else{ echo "Gagal Koneksi ke server"; } ?> <br><br> <a href="http://localhost/FOLDER/login.php">Back</a> </body> </html>

18 Hasil login

19 Form Input Login nama file : inputlogin.php
<html> <body> <form name="fdata" action="http://localhost/folder/savelogin.php" method="post"> <table border=“0"> <tr><td>Username</td><td><input type="text" name="pengguna"></td></tr> <tr><td>Password</td><td><input type="password" name="sandi"></td></tr> <tr><td>Otoritas</td> <td><select name="level"> <option value="1">Administrator <option value="2">Operator </select> </td></tr> <tr><td></td><td><input type="submit" name="btSimpan" value="Simpan"></td></tr> </table> </form> </body> </html>

20 Script simpan Login nama file : savelogin.php
<html> <body> <? $conn=mysql_connect("localhost","root","123"); if ($conn){ mysql_select_db("pengguna"); echo "Username=$pengguna<br>"; echo "Password=$sandi<br>"; echo "Otoritas=$level<br><br>"; $perintah="insert into login (username,password,level) values ('$pengguna','$sandi','$level')"; $hasil=mysql_query($perintah,$conn); if ($hasil){ echo "<br>Data telah tersimpan"; } mysql_close($conn); }else{ echo "Gagal Koneksi ke server"; ?> <br><br> <a href="http://localhost/FOLDER/inputlogin.php">Input Data login</a> <br> <a href="http://localhost/FOLDER/showlogin.php">Tampil Data login</a> </body> </html>

21 Tampilan savelogin.php

22 Script tampil Login nama file : showlogin.php
<html> <body> <? $conn=mysql_connect("localhost","root","123"); if ($conn){ mysql_select_db("pengguna"); $perintah="select * from login"; $hasil=mysql_query($perintah,$conn); $baris=mysql_fetch_row($hasil); if ($baris){ echo "<table border='1'><tr><td>Usernamee</td><td>Password</td><td>Otoritas</td></tr>"; do { list($username,$password,$level)=$baris; if ($level==1){ $otoritas="Admnistrator"; }else{ $otoritas="Operator"; } echo "<tr><td>$username</td>"; echo "<td>$password</td>"; echo "<td>$otoritas</td></tr>"; }while ($baris=mysql_fetch_row($hasil)); echo "</table>"; echo "Data tidak ada"; mysql_close($conn); echo "Gagal Koneksi ke server"; ?> <br><br> <a href="http://localhost/FOLDER/inputlogin.php">Input Data</a> </body> </html>

23 Tampilan showlogin.php

24 Form ganti password nama file : newpassword.php
<html> <body> <form name="fdata" action="http://localhost/folder/ubahpassword.php" method="post"> <table border=“0"> <tr><td>Username</td><td><input type="text" name="pengguna"></td></tr> <tr><td>Old Password</td><td><input type="password" name="sandilama"></td></tr> <tr><td>New Password</td><td><input type="password" name="sandibaru"></td></tr> <tr><td></td><td><input type="submit" name="btUbah" value="Ubah"></td></tr> </table> </form> </body> </html>

25 Script mengubah password namafile: ubahpassword.php
<html> <body> <? $conn=mysql_connect("localhost","root","123"); if ($conn){ mysql_select_db("pengguna"); $perintah="select * from login where username='$pengguna'"; $hasil=mysql_query($perintah,$conn); $baris=mysql_fetch_row($hasil); if ($baris){ $cek=false; do { list($username,$password,$level)=$baris; if($password==$sandilama){ $cek=true; $otoritas=$level; } }while ($baris=mysql_fetch_row($hasil)); if($cek){ echo "Username=$pengguna<br>"; echo "Password=$sandibaru<br>"; echo "Otoritas=$level<br><br>"; $perintah="update login set password='$sandibaru',level='$level' where username='$pengguna'"; if ($hasil){ echo "<br>Perubahan password telah tersimpan"; }else{ echo "Password anda salah!!!"; } }else{ echo "Username tidak terdaftar....";} mysql_close($conn); }else{ echo "Gagal Koneksi ke server"; } ?> <br><br> <a href="http://localhost/FOLDER/newpassword.php">Back</a> </body> </html>

26 Form Hapus data nama file: formhapus.php
<html> <body> <form name="fcari" method="post" action="http://localhost/folder/hapuslogin.php"> <table border="0"> <tr><td>Masukan username</td><td><input type="text" name="kunci"></td></tr> <tr><td></td><td><input type="submit" value="Hapus"></td></tr> </table> </form> </body> </html>

27 Script Hapus data nama file: hapuslogin.php
<html> <body> <? $conn=mysql_connect("localhost","root","123"); if ($conn){ mysql_select_db("pengguna"); $perintah="delete from login where username='$kunci'"; $hasil=mysql_query($perintah,$conn); if ($hasil){ echo "<br>Data telah terhapus"; }else{ echo "<br>Data tidak ditemukan"; } mysql_close($conn); echo "Gagal Koneksi ke server"; ?> <br><br> <a href="http://localhost/FOLDER/formhapus.php">Hapus Data login</a> <br> <a href="http://localhost/FOLDER/showlogin.php">Tampil Data login</a> </body> </html>

28

29 Index.php <html> <frameset rows="20%,80%">
<frame name="atas" src="http://localhost/folder/judul.php"> <frameset cols="20%,80%"> <frame name="kiri" src="http://localhost/folder/menu.php"> <frame name="kanan" src="http://localhost/folder/isi.php"> </frameset> </html>

30 Menu.php <html> <body>
<h2>Data Pengunjung</h2> <a href="http://localhost/FOLDER/input.php" target="kanan">Input Buku tamu</a><br> <a href="http://localhost/FOLDER/tampil.php" target="kanan">Tampil buku tamu</a><br> <br> <h2>Data Pengguna</h2> <a href="http://localhost/FOLDER/inputlogin.php" target="kanan">Input data pengguna</a><br> <a href="http://localhost/FOLDER/showlogin.php" target="kanan">Tampil data login</a><br> <a href="http://localhost/FOLDER/newpassword.php" target="kanan">Ganti Password</a><br> <a href="http://localhost/FOLDER/formhapus.php" target="kanan">Hapus data login</a><br> <a href="http://localhost/FOLDER/login.php" target="kanan">Login</a><br> </body> </html>

31 Judul.php <html> <body>
<H1 align="center">Dasar-dasar hubungan HTML, PHP dan MySQL Server</H1> <p align="center">Belajar bersama dengan orang-orang inforamatika</p> </body> </html>

32 Isi.php <html> <body>
<H3 align="center">Secara tersirat apa yang perlu diketahui...</H1> <p align="center">Setelah mengenal tag-tag HTML, tuntutan berikutnya adalah bagaimana HTML dapat mentransfer data ke database MySql menggunakan script PHP. Dalam memperlajari script PHP dituntut mendaptkan porsi yang lebih banyak daripada mempelajari HTML dan MySql itu sendiri. </p> </body> </html>

33 Session & Cookeis [akhir pertemuan]

34 Menampilkan data dg huruf dpn
<html> <body> <? $conn=mysql_connect("localhost","root","123"); if ($conn){ mysql_select_db("pengunjung"); $perintah="select * from bukutamu where nama like '$kunci%'"; $hasil=mysql_query($perintah,$conn); $baris=mysql_fetch_row($hasil); if ($baris){ echo "<table border='1'><tr><td>NAMA</td><td> </td><td>KOMENTAR</td></tr>"; do { list($nama,$ ,$komentar)=$baris; echo "<tr><td>$nama</td>"; echo "<td>$ </td>"; echo "<td>$komentar</td></tr>"; }while ($baris=mysql_fetch_row($hasil)); echo "</table>"; }else{ echo "Data tidak ada"; } mysql_close($conn); echo "Gagal Koneksi ke server"; echo "<br>"; for ($i=65; $i<91; $i++){ $huruf=chr($i); echo "| <a href='http://localhost/folder/kasus1.php?kunci=$huruf'>$huruf</a>"; echo " |"; ?> <br><br> <a href="http://localhost/FOLDER/input.php">Input Data</a> </body> </html>

35

36 Kasus 2: Hapus & Edit Login
<html> <body> <? $conn=mysql_connect("localhost","root","123"); if ($conn){ mysql_select_db("pengguna"); $perintah="select * from login"; $hasil=mysql_query($perintah,$conn); $baris=mysql_fetch_row($hasil); if ($baris){ ?> <table border='1'><tr><td>Usernamee</td><td>Password</td><td>Otoritas</td><td colspan="2"><div align="center">Perintah</div></td></tr> do { list($username,$password,$level)=$baris; if ($level==1){ $otoritas="Admnistrator"; }else{ $otoritas="Operator"; } <tr> <td><? echo $username ?></td> <td><? echo $password?></td> <td><? echo $otoritas?></td> <td><a href="http://localhost/folder/editk2.php?pengguna=<? echo $username ?>">Edit</a></td> <td><a href="http://localhost/folder/hapuslogin.php?kunci=<? echo $username ?>">Hapus</a></td> </tr> }while ($baris=mysql_fetch_row($hasil)); ?></table><? echo "Data tidak ada"; mysql_close($conn); echo "Gagal Koneksi ke server"; <br><br> <a href="http://localhost/FOLDER/inputlogin.php">Input Data</a> </body> </html>

37 Editk2.php <html> <body>
<form name="fdata" action="http://localhost/folder/ubahpassword.php" method="post"> <table border=“0"> <tr><td>Username</td> <td><input type="text" value="<? echo $pengguna ?>" name="pengguna"></td> </tr> <tr><td>Old Password</td><td><input type="password" name="sandilama"></td></tr> <tr><td>New Password</td><td><input type="password" name="sandibaru"></td></tr> <tr><td></td><td><input type="submit" name="btUbah" value="Ubah"></td></tr> </table> </form> </body> </html>

38


Download ppt "PHP dan MySQL (Studikasus: Login) Jumadi, S.T. Blog: jumadi.blog.ugm.ac.id Email: mcs.jumadi@mail.ugm.ac.id."

Presentasi serupa


Iklan oleh Google