1 / 27

Dasar Pemrograman PHP

Dasar Pemrograman PHP. HTML. Ceklist. Membuat halaman hello world Membuat tabel Membuat link / hyperlink Membuat formulir. Struktur direktori xampp. File pada web dengan alamat localhost disimpan pada direktory c:/xampp/htdocs/ Buat direktori dibawah nya sehingga terdapat direktori

saad
Download Presentation

Dasar Pemrograman PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dasar Pemrograman PHP HTML

  2. Ceklist • Membuat halaman hello world • Membuat tabel • Membuat link / hyperlink • Membuat formulir

  3. Struktur direktori xampp File pada web dengan alamat localhost disimpan pada direktory c:/xampp/htdocs/ Buat direktori dibawah nya sehingga terdapat direktori c:/xampp/htdocs/latphp Direktori tersebut menghasilkan alamat url http://localhost/latphp

  4. Hello world (hello1.php)http://localhost/latphp/hello1.php <html> <head> <title>hello world</title> </head> <body> Hello world </body> </html>

  5. Tabel 1 (tabel1.php) <body> <table border=1> <tr><td>no<td>nama<td>nilai <tr><td>1<td>mardi<td>70 <tr><td>2<td>siswo<td>80 <tr><td>3<td>utomo<td>90 </table> </body>

  6. Tabel 2 <body> <table border=1> <tr><td>no<td colspan=2>data <tr><td><td>nama<td>nilai <tr><td>1<td>mardi<td>70 <tr><td>2<td>siswo<td>80 <tr><td>3<td>utomo<td>90 </table> </body>

  7. Tabel 3 <table border=1> <tr><td>no<td>nama<td>MK<td>nilai <tr><td rowspan=2>1<td rowspan=2>mardi<td>jarkom<td>70 <tr><td>PTI<td>90 <tr><td rowspan=2>2<td rowspan=2>utomo<td>jarkom<td>60 <tr><td>PTI<td>80 </table>

  8. Tabel Latihan • Buat tabel isian BKD hanya dengan menggunakan notepad

  9. Sintaks PHP <html> <head> <title>hello world</title> </head> <body> <?php echo “Hello world”; ?> </body> </html>

  10. Variabel PHP Nama variabel diawali dengan tanda $ <?php $x=5; $y=7; $z=$x * $y; echo “$z”; ?>

  11. Jawaban Latihan <table border=1> <tr><td>x<td>y<td>z <?php $x=2; $y=3; $z=$x+$y; echo “<tr><td>$x<td>$y<td>$z”; ?> </table>

  12. Perulangan <?php echo “<table border=1>”; for($x=0;$x<10;$x++){ echo “<tr><td>$x”; } echo “</table>”; ?>

  13. Latihan Buat tabel perkalian 10x10

  14. Pencabangan <?php $loop=1; while($loop<10){ echo “$loop – “; if(($loop % 2) == 0) { echo “<br>”; } $loop=$loop+1; } ?>

  15. Membuat Link <a href=‘[url]’ >[teks]</a> <a href=‘http://localhost/latphp/tabel1.php’ >Tabel1</a> <a href=‘http://localhost/latphp/tabel2.php’ >Tabel2</a>

  16. Membuat Link Tugas: Buat link untuk masing-masing latihan yang telah dibuat. Hello1 Tabel1 Tabel2 Tabel3

  17. Membuat Formulir(cobafrm.php) <form method=‘post’ action=‘cobaform.php’> Masukan nama : <input type=‘text’ name=‘nama’><br> Jumlah MK : <select name=‘MK’> <option value=‘1’>1</option> <option value=‘2’>2</option> <option value=‘3’>3</option> </select> <br><input type=‘submit’ value=‘simpan’> </form>

  18. formulir Tambahkan sintak php di bagian atas formulir tadi <?php echo “Nama : $_REQUEST[nama] <br>”; echo “MK : $_REQUEST[MK]”; echo “<br><br><br>”; ?>

  19. Membuat Formulir(cobafrm.php) <form method=‘post’ action=‘cobaform.php’> Masukan nama : <input type=‘text’ name=‘nama’ value=‘mardi siswo’><br> Jumlah MK : <select name=‘MK’> <option value=‘1’>1</option> <option value=‘2’>2</option> <option value=‘3’>3</option> </select> <br><input type=‘submit’ value=‘simpan’> </form>

  20. Latihan buat formulir untuk penjumlahan Masukan angka 1 : [ ] Masukan angka 2 : [ ] [Hitung] Hasil penjumlahan angka1 dan angka2= ????

  21. Jawaban <form method=‘post’ action=‘tambah.php’> Angka 1 : <input type=‘text’ name=‘angka1’><br> Angka 2 : <input type=‘text’ name=‘angka2’><br> <input type=‘submit’ value=‘hitung’> </form> <?php $hasil=$_REQUEST[angka1]+$_REQUEST[angka2]; echo “<br> hasil penjumlahan adalah $hasil”; ?>

  22. Latihan • Buat formulir isian data dosen <form method=‘post’ action=‘inpdosen.php’> <table> <tr><td>Nama<td>:<td><input type=‘text’ name=‘nama’ size=100> <tr><td>NIY<td>:<td><input type=‘text’ name=‘NIY’ size=20> ……dst </table></form>

  23. Koneksi ke mysql <?php $db_username = "root"; $db_hostname = "localhost"; $db_password = "root"; $db_name = “unisbank"; //-------------------------------- $con = mysql_connect($db_hostname, $db_username, $db_password); $db = mysql_select_db($db_name, $con); //---------------------------------- $s="select * from dosen"; $r=mysql_query($s); While($w=mysql_fetch_array($r)){ echo "$w[NIY] - $w[Nama] <br>"; } ?>

  24. http://latphp/sql2.php?niy=

  25. http://latphp/sql2.php?nip=YS.2.. <?php $db_username = "root"; $db_hostname = "localhost"; $db_password = "root"; $db_name = “unisbank"; //-------------------------------- $con = mysql_connect($db_hostname, $db_username, $db_password); $db = mysql_select_db($db_name, $con); //---------------------------------- If($_REQUEST[btsimpan]==‘simpan’) { $s=“update dosen set nama=‘$_REQUEST[nama]’, alamat=‘$_REQUEST[alamat] where nip= ‘$_REQUEST[nip]’ "; $r=mysql_query($s); } $s="select Nama from dosen where nip= ‘$_REQUEST[nip]’ "; $r=mysql_query($s); If ($w=mysql_fetch_array($r)){ echo “<form method=‘post’ action=‘sql2.php’> Masukan nip : <input type=‘text’ name=‘nip’ value=‘$w[nip]’><br> Masukan nama : <input type=‘text’ name=‘nama’ value=‘$w[Nama]’><br> <input type=‘submit’ name=‘btsimpan’ value=‘simpan’></form>”; } ?>

  26. If ($w=mysql_fetch_array($r)){ echo “<a href=‘latphp/sql2.php?nip=$w[NIP]’>$w[NIP]</a>”; }

  27. Update [nama_tabel] set [nama_kolom1]=… , [nama_kolom2]=… where [kondisi] • Contoh ; Update dosen set nama=‘mardi siswo utomo’ where niy=‘0001’

More Related