WEB II PHP 11 odbc 2

1,403 views
1,339 views

Published on

Published in: News & Politics, Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,403
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

WEB II PHP 11 odbc 2

  1. 1. By I Wayan Simpen Pemrograman Web II With ODBC (Kont.)
  2. 2. Query Multi Table <ul><li>Studi Kasus  Sistem Informasi Perpustakaan (SIP) </li></ul><ul><li>Pada SIP terdapat skema database sebagai berikut: </li></ul><ul><ul><li>ANGGOTA( STB , nama, t4lahir, tglahir, jkel, alamat, telp, pasw) </li></ul></ul><ul><ul><li>BUKU( nktlg , judul, kdklas, kdpeng, kdpen, tahun, jumlah, terpinjam) </li></ul></ul><ul><ul><li>PENERBIT( kdpen , nmpen) </li></ul></ul><ul><ul><li>PENGARANG( kdpeng , nmpeng) </li></ul></ul><ul><ul><li>PINJAM( nktlg, STB , tgpinjam, tghrskem, sts) </li></ul></ul><ul><ul><li>KEMBALI( nktlg, STB , tgpinjam, tgkembali, sts) </li></ul></ul><ul><ul><li>USER( userid ,pasw) </li></ul></ul>
  3. 3. Struktur Tabel tabase PERPUS.MDB <ul><li>Tabel anggota </li></ul>  10 Text pasw    35 Text telp    35 Text alamat    10 Text jkel    Date/Time tglahir    35 Text t4lahir    35 Text nama    6 Text STB Width Type Field
  4. 4. Struktur Tabel tabase PERPUS.MDB <ul><li>Tabel Buku </li></ul>  Byte Number terpinjam    Interger Number jumlah  4  Text tahun    Integer Number kdpen    Integer Number kdpeng  Integer Number kdklas  100  Text judul  10  Text nktlg   Width Type Field
  5. 5. Struktur Tabel tabase PERPUS.MDB <ul><li>Tabel Kategori </li></ul><ul><li>Tabel Penerbit </li></ul><ul><li>Tabel Pengarang </li></ul>25 Text nmklas  Integer Number kdklas   Width Type Field 35 Text nmpen  Interger Number kdpen   Width Type Field 35 Text nmpeng  Integer Number kdpeng   Width Type Field
  6. 6. Struktur Tabel tabase PERPUS.MDB <ul><li>Tabel Kembali </li></ul><ul><li>Tabel User </li></ul><ul><li>Tabel Pinjam </li></ul>Yes/No sts    Date/Time tgkembali  Date/Time tgpinjam  10  Text nktlg  6  Text STB Width Type Field Yes/No sts    Date/Time tghrskem    Date/Time tgpinjam  10  varchar(10) nktlg  6 varchar(10) STB Width Type Field 10 Text pasw  10 Text userid  Width Type Field
  7. 7. Urutan Proses <ul><li>Web Page Sistem Informasi Perpustakaan Terdiri dari 2 (dua) bagian yaitu: </li></ul><ul><ul><li>Halaman Anggota/Umum </li></ul></ul><ul><ul><ul><li>Entri Member </li></ul></ul></ul><ul><ul><ul><li>Edit Member </li></ul></ul></ul><ul><ul><ul><li>Search Buku </li></ul></ul></ul><ul><ul><li>Halaman Admin/Pustakawan </li></ul></ul><ul><ul><ul><li>Entri Data (Buku, Penerbit, Klasifikasi, Pengarang) </li></ul></ul></ul><ul><ul><ul><li>Edit Data (Buku, Penerbit, Klasifikasi, Pengarang) </li></ul></ul></ul><ul><ul><ul><li>Transaksi (Peminjaman, Pengembalian) </li></ul></ul></ul><ul><ul><ul><li>Search Buku </li></ul></ul></ul>
  8. 8. Web Page Anggota/Umum
  9. 9. Web Page Member
  10. 10. Source Code Member <html> <head> <title>Anggota</title> </head> <body bgcolor=&quot;#F5F5F5&quot;> <table border=&quot;5&quot; align=&quot;center&quot;> <th>ANGGOTA</th> <tr><td> <form method=&quot;post&quot; action=&quot;save.anggota.php&quot;> <table> <tr> <td>Nomor Induk</td> <td><input type=&quot;text&quot; size=&quot;10&quot; name=&quot;nis&quot;></td> </tr> <tr> <td>Nama </td> <td> <input type=&quot;text&quot; size=&quot;35&quot; name=&quot;namaanggota&quot;></td> </tr> <tr> <td>Tempat Lahir </td> <td> <input type=&quot;text&quot; size=&quot;35&quot; name=&quot;t4lahir&quot;></td> </tr> Dieksekusi jika Tombol Submit di klik
  11. 11. <tr> <td>Tanggal Lahir</td> <td> <select name=&quot;tgl&quot;> <option value=&quot;0&quot; selected>Tanggal <?php for($i=1;$i<32;$i++) { if ($tgl==$i) $sel=&quot;SELECTED&quot;; else $sel=&quot;&quot;; print(&quot;<OPTION VALUE=&quot;$i&quot; $sel>$i&quot;); } ?> </option></select> <select name=&quot;bln&quot;> <option value=&quot;0&quot; selected>Bulan <?php for($i=1;$i<13;$i++) { $sel[$i]=&quot;&quot;; if ($i==$bln) $sel[$i] = &quot;SELECTED&quot;; }
  12. 12. print(&quot;<OPTION VALUE=&quot;1&quot; $sel[1]>Januari&quot;); print(&quot;<OPTION VALUE=&quot;2&quot; $sel[2]>Pebruari&quot;); print(&quot;<OPTION VALUE=&quot;3&quot; $sel[3]>Maret&quot;); print(&quot;<OPTION VALUE=&quot;4&quot; $sel[4]>April&quot;); print(&quot;<OPTION VALUE=&quot;5&quot; $sel[5]>Mei&quot;); print(&quot;<OPTION VALUE=&quot;6&quot; $sel[6]>Juni&quot;); print(&quot;<OPTION VALUE=&quot;7&quot; $sel[7]>Juli&quot;); print(&quot;<OPTION VALUE=&quot;8&quot; $sel[8]>Agustus&quot;); print(&quot;<OPTION VALUE=&quot;9&quot; $sel[9]>September&quot;); print(&quot;<OPTION VALUE=&quot;10&quot; $sel[10]>Oktober&quot;); print(&quot;<OPTION VALUE=&quot;11&quot; $sel[11]>November&quot;); print(&quot;<OPTION VALUE=&quot;12&quot; $sel[12]>Desember&quot;); ?> </option></select> <select name=&quot;thn&quot;> <option value=&quot;0&quot; selected>Tahun <?php $sekarang=(integer) date (&quot;Y&quot;);
  13. 13. for($i=1960;$i<=$sekarang;$i++) { if ($thn==$i) $sel=&quot;SELECTED&quot;; else $sel=&quot;&quot;; print(&quot;<OPTION VALUE=&quot;$i&quot; $sel>$i&quot;); } ?> </option></select> </td> </tr> <tr> <td>Jenis Kelamin</td> <td> <input type=&quot;Radio&quot; name=&quot;jkel&quot; value=&quot;Laki-Laki&quot; CHECKED>Laki-Laki <input type=&quot;Radio&quot; name=&quot;jkel&quot; value=&quot;Perempuan&quot;>Perempuan</td> </tr> <tr> <td>Alamat</td> <td> <input type=&quot;text&quot; size=&quot;35&quot; name=&quot;alamat&quot;></td> </tr>
  14. 14. <tr> <td>Telpon</td> <td><input type=&quot;text&quot; size=&quot;15&quot; name=&quot;telpon&quot;></td> </tr> <tr> <td>Password</td> <td><input type=&quot;Password&quot; size=&quot;10&quot; name=&quot;pass1&quot;> Password Sekali lagi <input type=&quot;Password&quot; size=&quot;10&quot; name=&quot;pass2&quot;> </td> </tr> <tr> <td colspan=2 align=&quot;center&quot;><input type=&quot;submit&quot; value=&quot;Save&quot;> <input type=&quot;reset&quot; value=&quot;Batal&quot;></td> </tr> </table> </form> </td></tr></table> </body> </html>
  15. 15. Source Save.Anggota.php <?php //untuk PHP5 $nis=$_POST[&quot;nis&quot;]; $namaanggota=$_POST[&quot;namaanggota&quot;]; $t4lahir=$_POST[&quot;t4lahir&quot;]; $jkel=$_POST[&quot;jkel&quot;]; $alamat=$_POST[&quot;alamat&quot;]; $telpon=$_POST[&quot;telpon&quot;]; $pass1=$_POST[&quot;pass1&quot;]; $pass2=$_POST[&quot;pass2&quot;]; $thn=$_POST[&quot;thn&quot;]; $bln=$_POST[&quot;bln&quot;]; $tgl=$_POST[&quot;tgl&quot;]; if (empty($nis) or empty($namaanggota) or empty($alamat) or empty($telpon) or empty($userid) or empty($pass1) or empty($pass2)) { print(&quot;<b><font color=red>Maaf</font></b><br>&quot;); print(&quot;Data Anda gagal diposting karena Tidak Lengkap&quot;); exit(); } Ambil data dari FORM
  16. 16. if ($pass1<>$pass2) { print(&quot;<b><font color=red>Maaf</font></b><br>&quot;); print(&quot;<b>Password Anda tidak sama....!</b>&quot;); exit(); } $pass1 = md5($pass1); include(&quot;conect.inc.php&quot;); $Tsql=&quot;SELECT stb from anggota where stb=‘$nis’&quot;; $hasil=odbc_do($bukadb,$Tsql); $baris=odbc_fetch_row($hasil); if ($baris==TRUE) die (&quot;Nomor Induk $nis sudah menjadi member&quot;); $format_tanggal=sprintf(&quot;%02d/%02d/%02d&quot;, $tgl, $bln,$thn); Password di Enkripsi Gabungkan bulan, tanggal, dan tahun
  17. 17. $Tsql=&quot;INSERT INTO anggota &quot;. &quot;(stb,Nama,t4lahir, tglahir, Jkel, alamat, Telp, pasw)&quot;. &quot;VALUES ('$nis', '$namaanggota', '$t4lahir', '$format_tanggal', '$jkel',”. “ '$alamat', '$telpon', '$userid', '$pass1')&quot;; if (odbc_do($bukadb,$Tsql)) { print(&quot;Selamat<br>&quot;); print(&quot;Identitas Anda Telah diCatat&quot;); } else { print(&quot;M a a f<br>&quot;); print(&quot;Perekaman data gagal dilakukan&quot;); } ?> </body> </html> Query untuk menambah data Eksekusi Query Pesan Jika Eksekusi Gagal
  18. 18. Edit Member
  19. 19. Cource Login.php <HTML> <BODY> <center> <table border=1> <tr><td align=&quot;center&quot;><font color=&quot;blue&quot;> <b>Login Member</b> </td> </tr> <tr> <td> <br> <form action=&quot; ubanggt.php &quot; method=&quot;POST&quot;> <table border=0> <tr> <td><font size=&quot;2&quot; color=&quot;#ff0000&quot;>User </td></font> <td><input type=text name=&quot;pemakai&quot; size=10></td> </tr>
  20. 20. Cource Login.php (Kont.) <tr> <td><font size=&quot;2&quot; color=&quot;#ff0000&quot;>Password</font></td> <td><input type=password name=&quot;sandi&quot; size=10></td> </tr> <tr> <td align=right colspan=2><input type=submit value=&quot;Go&quot;></td> </tr> </table> </form> </td></td> </center> </BODY> </HTML>
  21. 21. Cource ubanggt.php <?php session_start(); $pemakai=$_POST['pemakai']; $sandi=$_POST['sandi']; include &quot;otentik.inc&quot;; if (! empty($pemakai)) $sesi_user=$pemakai; if (! empty($sandi)) $sesi_pass=$sandi; if (! otentikasi($sesi_user,$sesi_pass)) { $msg=&quot;Harap isi dengan benar&quot;; $alamat=&quot;http://localhost/perpusodbc/index.php&quot;; //header(&quot;Location: $alamat?mag=$msg&quot;); exit(); } session_register(&quot;$sesi_user&quot;); session_register(&quot;$sesi_pass&quot;); Aktifkan Session Gabungkan Fungsi Hak akses Periksa Hak akses Resgistrasi Hak akses
  22. 22. Cource ubanggt.php include(&quot;conect.inc.php&quot;); $Tsql= &quot;SELECT * from anggota where STB = '$pemakai'&quot;; $hasil=odbc_do($bukadb,$Tsql); if (!$hasil) die (&quot;User ID $pemakai belum menjadi member&quot;); $nis=odbc_result($hasil,1); $nama=odbc_result($hasil,2); $t4lahir=odbc_result($hasil,3); $thn=substr(odbc_result($hasil,4),0,4); $bln=substr(odbc_result($hasil,4),5,2); $tgl=substr(odbc_result($hasil,4),8,2); $jkel=odbc_result($hasil,5); $alamat=odbc_result($hasil,6); $telp=odbc_result($hasil,7); ?> Gabungkan web page Koneksi Database Query u/cari member Ambil Item Data dari Table
  23. 23. Cource ubanggt.php (Kont.) <HTML> <body bgcolor=&quot;#F5F5F5&quot;> <div align=center> <table border=&quot;5&quot; align=&quot;center&quot;> <tr> <td align=center valign=bottom> <h2>Update Member</h2> </td></tr> <tr><td> <form action=&quot; upsave.php &quot; method=&quot;POST&quot;> <table border=0> <tr> <td>Nomor Induk</td> <td> <?php print(&quot;<b>;&nbsp;$nbsp;$nis</b>”); print(&quot;<Input type=hiddent name=&quot;nis&quot; size=6 VALUE= $nis >&quot;); ?> </td> </tr> Tampilkan STB
  24. 24. Cource ubanggt.php (Kont.) <tr> <td>Nama</td> <td> <?php print(&quot;<Input type=text name=&quot;nama&quot; size=35 VALUE=&quot;$nama&quot;>&quot;); ?> </td> </tr> <tr> <td>Tempat Lahir</td> <td> <?php print(&quot;<Input type=text name=&quot;t4lahir&quot; size=35 VALUE=&quot;$t4lahir&quot;>&quot;); ?> </td> </tr> Tampilkan NAMA TampilkanTempat Lahir
  25. 25. Cource ubanggt.php (Kont.) <tr> <td>Tanggal Lahir</td> <td> <select name=&quot;tgl&quot;> <option value=&quot;0&quot; selected>Tanggal <?php for($i=1;$i<32;$i++) { if ($tgl==$i) $sel=&quot;SELECTED&quot;; else $sel=&quot;&quot;; print(&quot;<OPTION VALUE=&quot;$i&quot; $sel>$i&quot;); } ?> </option> </select>
  26. 26. <select name=&quot;bln&quot;> <option value=&quot;0&quot; selected>Bulan <?php for($i=1;$i<13;$i++) { $sel[$i]=&quot;&quot;; if ($i==$bln) $sel[$i] = &quot;SELECTED&quot;; } print(&quot;<OPTION VALUE=&quot;1&quot; $sel[1]>Januari&quot;); print(&quot;<OPTION VALUE=&quot;2&quot; $sel[2]>Pebruari&quot;); print(&quot;<OPTION VALUE=&quot;3&quot; $sel[3]>Maret&quot;); print(&quot;<OPTION VALUE=&quot;4&quot; $sel[4]>April&quot;); print(&quot;<OPTION VALUE=&quot;5&quot; $sel[5]>Mei&quot;); print(&quot;<OPTION VALUE=&quot;6&quot; $sel[6]>Juni&quot;); print(&quot;<OPTION VALUE=&quot;7&quot; $sel[7]>Juli&quot;); print(&quot;<OPTION VALUE=&quot;8&quot; $sel[8]>Agustus&quot;); print(&quot;<OPTION VALUE=&quot;9&quot; $sel[9]>September&quot;); print(&quot;<OPTION VALUE=&quot;10&quot; $sel[10]>Oktober&quot;); print(&quot;<OPTION VALUE=&quot;11&quot; $sel[11]>November&quot;); print(&quot;<OPTION VALUE=&quot;12&quot; $sel[12]>Desember&quot;); ?> </option></select> Tampilkan Bulan jika sama dengan $bln
  27. 27. Cource ubanggt.php (Kont.) <select name=&quot;thn&quot;> <option value=&quot;0&quot; selected>Tahun <?php $sekarang=(integer) date (&quot;Y&quot;); for($i=1960;$i<=$sekarang;$i++) { if ($thn==$i) $sel=&quot;SELECTED&quot;; else $sel=&quot;&quot;; print(&quot;<OPTION VALUE=&quot;$i&quot; $sel>$i&quot;); } ?> </option></select> </td> </tr> TampilkanTahun lahir jika = Tahun di file
  28. 28. <tr> <td >Jenis Kelamin</td> <td> <?php $checkedP=&quot;&quot;; $checkedW=&quot;&quot;; if ($jkel==&quot;Laki-Laki&quot;) $checkedP=&quot;CHECKED&quot;; else $checkedW=&quot;CHECKED&quot;; print(&quot;<Input type=Radio name=&quot;jkel&quot; value=&quot;Laki-Laki“ $checkedP>Pria&quot;); print(&quot;<Input type=Radio name=&quot;jkel&quot; value=&quot;Perempuan“ $checkedW>Wanita&quot;); ?> </td> </tr> <tr><td>Alamat</td> <td><?php print(&quot;<Input type=text name=&quot;alamat&quot; size=&quot;35“ VALUE=&quot;$alamat&quot;>&quot;); ?> </td> </tr>
  29. 29. Cource ubanggt.php (Kont.) <tr> <td>Telpon</td> <td> <?php print(&quot;<input type=&quot;text&quot; size=&quot;15&quot; name=&quot;telpon“ value=$telp>&quot;); ?> </td> </tr> <tr> <td>User ID</td> <td> <?php print(&quot;<input type=&quot;text&quot; size=&quot;10&quot; name=&quot;userid“ value=$userid>&quot;); ?> </td> </tr> Tampilkan nomor Telepon Tampilkan User ID
  30. 30. Cource ubanggt.php (Kont.) <tr> <td>Password</td> <td><input type=&quot;Password&quot; size=&quot;10&quot; name=&quot;pass1&quot;> Password Sekali lagi <input type=&quot;Password&quot; size=&quot;10&quot; name=&quot;pass2&quot;> </td> </tr> </tr> <tr> <td align= &quot;center&quot; colspan=&quot;2&quot; ><input type=submit value=&quot;Save&quot;> <input type=Reset value=&quot;Batal&quot;></td> </tr> </table> </form></font> </td></tr> </table></div> </BODY> </HTML>
  31. 31. Cource Code upsave.php <html><body> <?php $nis=$_POST[&quot;nis&quot;]; $nama=$_POST[&quot;nama&quot;]; $t4lahir=$_POST[&quot;t4lahir&quot;]; $thn=$_POST[&quot;thn&quot;]; $bln=$_POST[&quot;bln&quot;]; $tgl=$_POST[&quot;tgl&quot;]; $jkel=$_POST[&quot;jkel&quot;]; $alamat=$_POST[&quot;alamat&quot;]; $telp=$_POST[&quot;telpon&quot;]; $pass1=$_POST[&quot;pass1&quot;]; $pass2=$_POST[&quot;pass2&quot;]; if (empty($nama) or empty($alamat) or empty($telp) or empty($userid) or empty($pass1) or empty($pass2)) { print(&quot;<b><font color=red>Maaf</font></b><br>&quot;); print(&quot;Data Anda gagal diposting karena Tidak Lengkap&quot;); exit(); } Ambil data item dari FORM
  32. 32. Cource Code upsave.php (Kont) if (!($pass1==$pass2)) { print(&quot;<b><font color=red>Maaf</font></b><br>&quot;); print(&quot;Password yang Anda berikan tidak sama&quot;); exit(); } include &quot;conect.inc.php&quot;; $pass1 = md5($pass1); $format_tanggal=sprintf(&quot;%02d/%02d/%02d&quot;,$bln,$tgl,$thn); $query=&quot;UPDATE anggota&quot;. &quot;SET nama='$nama', t4lahir='$t4lahir', tglahir='$format_tanggal', &quot;. &quot;jkel='$jkel', alamat='$alamat', telp='$telp', &quot;. &quot;pasw='$pass1' WHERE STB='$nis'&quot;; TampilkanPesan jika password tidak sama Format Tangal Lahir Query UPDATE data
  33. 33. Cource Code upsave.php (Kont) if (odbc_do($bukadb,$quey)) { print(&quot;Selamat<br>&quot;); print(&quot;Identitas $nis Telah Diubah&quot;); } else { print(&quot;M a a f<br>&quot;); print(&quot;Update data dengan nis= $nis Gagal dilakukan&quot;); } ?> </body> </html> Eksekusi UPDATE data
  34. 34. Cource otentik.inc <?php include &quot;umum.inc&quot;; function otentikasi($pemakai, $sandi) { global $nama_user, $password, $database; $bukadb=odbc_connect($database, $nama_user, $password); if (! $bukadb) return FALSE; $Tsql=&quot;SELECT * from anggota where STB='$pemakai'&quot;; $hasil=odbc_do($bukadb,$Tsql); if (! $hasil) return FALSE; $pasw=odbc_result($hasil,8); $pass1=substr(md5($sandi),0,10); if ($pasw==$pass1) return TRUE; else { print(&quot;Sory Connect ke Database Gagal...<br>&quot;); return FALSE; } } ?> Field Passwod Cari userid Variabel
  35. 35. Source umum.inc <?php $nama_user = &quot;&quot;; $password = &quot;&quot;; $database = &quot;perpus&quot;; function header_dinamis() { header(&quot;Expires: 10 Desember 2005 17:00:00 GMT&quot;); header(&quot;Last-Modified:&quot;. gmdate(&quot;D, d M Y M:i:s&quot;)); if ($SERVER_PROTOCOL == &quot;HTTP/0.1&quot;) header(&quot;Pragma: no-cache&quot;); else header(&quot;Cache-Control: no-cache, must-revalidate&quot;); } ?>
  36. 36. Source Connect.inc.php <?php $nama_user = &quot;&quot;; $password = &quot;&quot;; $database = &quot;Perpus&quot;; $bukadb=odbc_connect($database,$nama_user,$password); if(! $bukadb) die(&quot;Database tak dapat dibuka&quot;); ?>
  37. 37. SAMPAI JUMPA MINGGU DEPAN TERIMAKASIH

×