Dokumen tersebut merupakan panduan pengembangan aplikasi dengan PHP yang membahas tujuan PHP untuk mengembangkan aplikasi web berbasis database, instalasi PHP dan MySQL, dasar-dasar PHP seperti variabel, operator, kontrol struktur, array, fungsi, serta contoh kode PHP untuk membuat form dan bekerja dengan HTML.
Laporan Guru Piket untuk Pengisian RHK Guru Pengelolaan KInerja Guru di PMM
MEMBUAT APLIKASI DENGAN PHP
1. MEMBUAT APLIKASI
DENGAN PHP
Agus Supriatna
Microsoft Certified Professional Developer
www.asupna.com
@agusSupark
asupriatna@teken.co.id
2. PURPOSE
Dengan pesatnya perkembangan Internet dan World Wide Web ada
peningkatan permintaan untuk pengembang dengan kemampuan untuk
melakukan manipulasi Web data lebih maju.
Siswa yang terlibat dalam pengembangan Web statis membutuhkan teknik
untuk memanipulasi konten Web sehingga web menjadi dinamis.
Tujuan dari program PHP adalah alat dan teknik untuk mengembangkan lebih
dinamis Web berbasis aplikasi, dengan manipulasi data yang disimpan dalam
database online
4. 1. INTRODUCTION
PHP (Personal Home Page Tools) created by Rasmus Lerdorf In 1994, umumnya
digunakan untuk:
1.
Melakukan fungsi sistem: membuat, membuka, membaca dari, menulis, dan
menutup file di sistem, menjalankan perintah sistem, membuat direktori, dan
mengubah hak akses.
2.
Mengumpulkan data dari bentuk: menyimpan data ke file, mengirim data melalui email, mengembalikan data dimanipulasi untuk pengguna.
3.
Akses database dan menghasilkan konten on-the-fly, atau membuat antarmuka Web
untuk menambahkan, menghapus, dan memodifikasi elemen-elemen dalam
database Anda.
4.
Mengatur cookie dan variabel akses.
5.
Otentikasi pengguna PHP untuk membatasi akses ke bagian situs Web Anda.
6.
Membuat gambar on-the-fly.
7.
Enkripsi data.
5. INSTALL
Xampp (Apache Web Server, PHP, Mysql)
Front end for the MySQL database server
PHP Editor Eclipse, Notepad++
6.
7. 2. WORKING WITH HTML
<html>
<head><title>PHP Test</title></head>
<body>
<?php echo '<p>Hello World Saya Menggunakan PHP</p>'; ?>
<table>
<tr> <th>Nama</th><th>Umur</th></tr>
<tr><td>Bagus</td><td>17 tahun</td></tr>
</table>
</body>
</html>
8. 2. WORKING WITH HTML
FORM
<form action=“handleForm.php" method="post">
<p>Nama: <input type="text" name=“Nama" /></p>
<p>Umur: <input type="text" name=“Umur" /></p>
<p>Komentar: <textarea rows=5 cols=40 name=“Komentar”> </textarea>
<p><input type="submit" name=“Simpan” value=“simpan”/>
<input type=“reset" name=“Clear” value=“Hapus Form”/>
</p>
</form>
9. COMMENTING YOUR CODE
1. HTML comments <!—and —>tags.
<!— logo graphic goes here —>
2. PHP comments // ; # ; /* and */
// this is a comment in PHP code
# This is shell-style style comment
/* This begins a C-style comment that runs
onto two lines */
10. 3. GETTING STARTED WITH
VARIABLES
1. Variable Scalar, berisi satu nilai dalam satu waktu
• Integers
• floating poin numbers (floats/doubles).
• Strings.Text and/or numeric yg ada diantara double quotes (" ") or
single quotes (' ')
2. Variable Arrays, berisi sejumlah nilai dan array lain sehingga membentuk
multidimensi array
3. HTML Variabel, variable yg didapat dari HTML form atau URL link
4. Supperglobal Variable, variable yg sudah ada di php engine
11. VARIABLE SCOPE
1.
2.
Sigle Scope
Global Scope dan Local Scope
<?php
var $r = 'I am r.';
class foo {
var $bar = 'I am bar.';
var $arr = array('I am A.', 'I am B.', 'I am
C.');
}
$foo = new foo();
$bar = 'bar';
$baz = array('foo', 'bar', 'baz', 'quux');
echo $foo->$bar . "n";
echo $foo->$baz[1] . "n";
?>
13. 4. OPERATORS
Assignment Operator :
=, += , -= , and .=
Arithmetic Operator:
Addition(+), subtraction(-), multiplication(*), division(/), modulus(%)
Comparison Operator
equal to (==), not equal to (!=), greater than (>), less than(<), greater than or equal to (>=),
less than or equal to (<=)
(&&) and; (||) or ; NOT (!).
16. 7. FUNCTIONS
function function_name($arg_1, $arg_2, ..., $arg_n)
{
code_line1;
code_line2;
code_line3;
return ($value); //stops execution of the function and returns its argument as
the value at the point where the function was called.
}
requirementsPre-knowledge on the development of static Web based applications (HTML). Internet access to the course material, e-mail facility and discussion forum on the course Web site.
Go to Control Panel > Administrative Tools > ServicesFind ”World Wide Web Publishing Service”Right click and select “Stop”Right click and select “Properties”, then change “Startup type” to “Manual”
Hello.phpHello.html
Entering comments in documents helps you (and others who might have to edit your document later) keep track of areas of large documents.
$ex += 1; // Assigns the value of ($ex + 1) to $ex. // If $ex = 2, then the value of ($ex += 1) is 3.$ex -= 1; // Assigns the value of ($ex - 1) to $ex. // If $ex = 2, then the value of ($ex -= 1) is 1.$ex .= "coffee"; // Concatenates (adds to) a string. If $ex = "I like” // then the value of ($ex .= "coffee") is "I likeArithmatic$c = $a + $b; // $c = 9$c = $a - $b; // $c = 1$c = $a * $b; // $c = 20$c = $a / $b; // $c = 1.25$c = $a % $b; // $c = 1In the following examples, $a = 5and $b = 4.• Is $a == $b?No; 5 does not equal 4. The comparison is FALSE.• Is $a != $b?Yes; 5 does not equal 4. The comparison is TRUE.• Is $a > $b?Yes; 5 is greater than 4. The comparison is TRUE.• Is $a < $b?No; 5 is not less than 4. The comparison is FALSE.• Is $a >= $b?Yes; although 5 does not equal 4, 5 is greater than 4. The comparison is TRUE.• Is $a <= $b?No; 5 does not equal 4, and 5 is not less than 4. The comparison is FALSE.Logical// secret number 5if ($guess == "5") { echo "That's the right number!";} else { echo "Sorry. Bad guess.";}$drink1 = "coffee";$drink2 = "milk"; if (($drink1 == "coffee") || ($drink2 == "coffee")) { echo "I'm happy!"; } else { echo "I still need caffeine."; }<?php $price = 10.00; $sales_tax = .0825; $quantity = 4; $sub_total = $price * $quantity; $sales_tax_amount = $sub_total * $sales_tax; $grand_total = $sub_total + $sales_tax_amount; echo "<P>You ordered $quantity bags of coffee.</p>"; echo "<P>Bags of coffee are $price each.</p>"; echo "<P>Your subtotal is $sub_total.</p>"; echo "<P>Sales tax is $sales_tax in this location.</p>"; echo "<P>$sales_tax_amount has been added to your order.</p>"; echo "<P>You owe $grand_total for your coffee.</p>";?>
<?php/** This is an array with some data we want to modify* when running through the for loop.*/$people = array(array('name' => 'Kalle', 'salt' => 856412),array('name' => 'Pierre', 'salt' => 215863));for($i = 0; $i < count($people); ++$i) {$people[$i]['salt'] = mt_rand(000000, 999999);}?>
Var_dump()Print_r()<?php// Create a simple array.$array = array(1, 2, 3, 4, 5);print_r($array);// Now delete every item, but leave the array itself intact:foreach ($array as $i => $value) {unset($array[$i]);}print_r($array);// Append an item (note that the new key is 5, instead of 0).$array[] = 6;print_r($array);// Re-index:$array = array_values($array);$array[] = 7;print_r($array);?>