<html>
<head>
<title>Latihan Link Dinamis</title>
</head>
<body>
<!–Link dinamis–>
<a href="?konten=1">Konten 1</a> | <a href="?konten=2">Konten 2</a><br>
<!–Proses PHP–>
<?php
if($_GET[konten] == 1) {
echo "<h2>Ini Konten Pertama !</h2>";
}
elseif($_GET[konten] == 2) {
echo "<h2>Ini Konten Kedua !</h2>";
}
else {
echo "<h2>Pilih Konten !</h2>";
}
?>
</body>
</html>
Nahh gini kalian bisa memanfaatkan metode pengiriman Get untuk link dinamis, jadi penulisannyadokumen.php?variabel=nilai, seperti itu, nanti hasilnya akan sama dengan kalian mengirim sebuah nilai dari variabel menggunakan form dengan metode pengiriman Get, Variabel yang dikirim dengan link dinamis dapat lebih dari 1, nah penjelasannya dokumen.php adalah tujuan / action, kalo masih di dokumen yang sama, kosongkan saja, jadi bisa ditulis seperti ini ?variabel=nilai, bahkan kalian bisa mengirim lebih dari satu variabel, contoh ?variabel1=nilai1&variabel2=nilai2, setiap variabel di batasi oleh tanda & “and” gimana, paham kan??
Senin, 19 Agustus 2013
Get di php
<html>
<head>
<title>Latihan Form dengan PHP</title>
</head>
<body>
<!–Membuat Form di HTML–>
<form action="<? PHP_SELF ?>" method="get">
Masukan nama : <input type="text" name="nama"><input type="submit" name="kirim" value="Kirim">
</form>
<!–Memulai PHP disini–>
<?php
if($_GET[kirim]) { //Jika tombol Kirim di tekan
if(!empty($_GET[nama])) { //Jika input Field nama tidak kosong
echo "Selamat datang " . $_GET[nama] . "di Program PHP";
}
else { //Jika input Field nama kosong
echo "Maaf, silahkan di isi terlebih dahulu";
}
}
?>
</body>
</html>
<head>
<title>Latihan Form dengan PHP</title>
</head>
<body>
<!–Membuat Form di HTML–>
<form action="<? PHP_SELF ?>" method="get">
Masukan nama : <input type="text" name="nama"><input type="submit" name="kirim" value="Kirim">
</form>
<!–Memulai PHP disini–>
<?php
if($_GET[kirim]) { //Jika tombol Kirim di tekan
if(!empty($_GET[nama])) { //Jika input Field nama tidak kosong
echo "Selamat datang " . $_GET[nama] . "di Program PHP";
}
else { //Jika input Field nama kosong
echo "Maaf, silahkan di isi terlebih dahulu";
}
}
?>
</body>
</html>
Form Login
form_login.php
<html>
<head>
<title>Form Login</title>
</head>
<body>
<!–Memulai Form HTML–>
<form action="proses.php" method="post">
<pre>
Login Anggota
User : <input type="text" name="user">
Pass : <input type="password" name="pass">
<input type="submit" name="masuk" value="Login"
>
</pre>
</form>
</body>
</html>
proses.php
</html><html>
<head>
<title>Proses Login</title>
</head>
<body>
<?php
if($_POST) {
if(isset($_POST[user]) and isset($_POST[pass])) {
if($_POST[user] == "Amri" and $_POST[pass] == "alunagutawa") {
echo "Selamat datang Amri Multimedia";
}
else {
echo "Maaf, User atau Password anda salah !";
}
}
else {
echo "Mohon dilengkapi !";
}
}
?>
</body>
RINGKASAN BELAJAR PHP
Tabel Sql :
create table if not exists `latihanprasidang` (
`id`int(12)not null auto_increment,
`nama`varchar(15)not null,
`alamat`varchar(15)not null,
`kodepos`int(5)not null,
primary key(`id`));
Index.php
<form action=input.php method=POST>
nama:<input type=text name=nama><br>
alamat:<input type=text name=alamat><br>
kode POS: <input type=text name=kodepos><br>
<input type=sumit name=goes value=simpan>
Tampil.php
<table border=1>
<tr><td>no</td><td>nama</td><td>alamat</td><td>kodepos</td><td>edit</td><td>hapus</td></tr>
<?php
include "koneksi.php";
$m=mysql_query("select * from latihanprasidang");
$no=1;
while($w=mysql_fetch_array($m)){
echo"<tr><td>$no</td>
<td>$w[nama]</td>
<td>$w[alamat]</td>
<td>$w[kodepos]</td>
<td><a href=edit.php?id=$w[id]>edit</a></td><td><a href=hapus.php?id=$w[id]>hapus</a></td>
</tr>";
$no++;
}
?>
</table>
Edit.php
<?php
include "koneksi.php";
$id = $_GET['id'];
$edit = mysql_query("SELECT * FROM latihanprasidang WHERE id='$id'");
$r = mysql_fetch_array($edit);
?>
<form method="post" action="update.php">
<input type=hidden name=id value="<?php echo $id;?>">
<table border="1">
<tr>
<td>EDIT</td>
</tr>
<tr>
<td>nama</td>
<td><input name="nama" type="text" value="<?php echo $r['nama'];?>" /></td>
</tr>
<tr>
<td>Alamat</td><td> <input name="alamat" type="text" value="<?php echo $r['alamat'];?>" /></td>
</tr>
<tr><td>kode pos</td><td><input type=text name=kodepos value="<?php echo $r['kodepos'];?>"></td>
</tr></table>
<input type=submit name=submit value=update>
Update.php
<?php
include "koneksi.php";
mysql_query("update latihanprasidang set
nama='$_POST[nama]', alamat='$_POST[alamat]',
kodepos='$_POST[kodepos]' where id='$_POST[id]'");
header('location:latihanpra.php');
?>
hapus.php
<?php
include "koneksi.php";
mysql_query("delete from latihanprasidang where id='$_GET[id]'");
header("location:latihanpra.php");
?>
Koneksi.php
<?php
mysql_connect("localhost","root","1");
mysql_select_db("latihanpra2");
?>
- See more at: http://miswanphp.blogspot.com/2013/01/membuat-inputtampiledit-dan-hapus.html#sthash.A7luUAS7.dpuf
create table if not exists `latihanprasidang` (
`id`int(12)not null auto_increment,
`nama`varchar(15)not null,
`alamat`varchar(15)not null,
`kodepos`int(5)not null,
primary key(`id`));
Index.php
<form action=input.php method=POST>
nama:<input type=text name=nama><br>
alamat:<input type=text name=alamat><br>
kode POS: <input type=text name=kodepos><br>
<input type=sumit name=goes value=simpan>
Tampil.php
<table border=1>
<tr><td>no</td><td>nama</td><td>alamat</td><td>kodepos</td><td>edit</td><td>hapus</td></tr>
<?php
include "koneksi.php";
$m=mysql_query("select * from latihanprasidang");
$no=1;
while($w=mysql_fetch_array($m)){
echo"<tr><td>$no</td>
<td>$w[nama]</td>
<td>$w[alamat]</td>
<td>$w[kodepos]</td>
<td><a href=edit.php?id=$w[id]>edit</a></td><td><a href=hapus.php?id=$w[id]>hapus</a></td>
</tr>";
$no++;
}
?>
</table>
Edit.php
<?php
include "koneksi.php";
$id = $_GET['id'];
$edit = mysql_query("SELECT * FROM latihanprasidang WHERE id='$id'");
$r = mysql_fetch_array($edit);
?>
<form method="post" action="update.php">
<input type=hidden name=id value="<?php echo $id;?>">
<table border="1">
<tr>
<td>EDIT</td>
</tr>
<tr>
<td>nama</td>
<td><input name="nama" type="text" value="<?php echo $r['nama'];?>" /></td>
</tr>
<tr>
<td>Alamat</td><td> <input name="alamat" type="text" value="<?php echo $r['alamat'];?>" /></td>
</tr>
<tr><td>kode pos</td><td><input type=text name=kodepos value="<?php echo $r['kodepos'];?>"></td>
</tr></table>
<input type=submit name=submit value=update>
Update.php
<?php
include "koneksi.php";
mysql_query("update latihanprasidang set
nama='$_POST[nama]', alamat='$_POST[alamat]',
kodepos='$_POST[kodepos]' where id='$_POST[id]'");
header('location:latihanpra.php');
?>
hapus.php
<?php
include "koneksi.php";
mysql_query("delete from latihanprasidang where id='$_GET[id]'");
header("location:latihanpra.php");
?>
Koneksi.php
<?php
mysql_connect("localhost","root","1");
mysql_select_db("latihanpra2");
?>
- See more at: http://miswanphp.blogspot.com/2013/01/membuat-inputtampiledit-dan-hapus.html#sthash.A7luUAS7.dpuf
Latihan 6
6. Penyimpanan
file yang di-Upload, dengan nama file yang tersimpan sama semuanya.
Sebelum
menjalankan program dibawah ini, maka register_globals yang ada di php.ini
harus di-on-kan terlebih dahulu.
a. Untuk membuat
inputan, dan beri nama file : f.php
<html>
<head>
<title>Form untuk input nama
file</title>
</head>
<body>
<h1>Input
nama file untuk Upload</h1>
<br>Klik Browse untuk memilih !
<form
enctype="multipart/form-data" method="post"
action="f1.php">
<input
type="hidden" name="MAX_FILE_SIZE"
value="10000">
Nama
File : <input type="file" name="file1"
size="30">
<br>
<input
type="submit" value="Upload">
</form>
</body>
</html>
b. Buat file
untuk memproses variabel, beri nama filenya : f1.php, hasil upload bisa
dilihat di direktori tempat menyimpan file php.
<html>
<head>
<title></title>
</head>
<body>
<h1>Simpan
file yang diupload</h1>
<br>
<?
if
($file1!="none") {
copy("$file1","hasilupload.txt")
or
die ("No files");
}
else
{
die("Tidak ada file yang
diupload");
}
?>
</body>
</html>
KETERANGAN :
Pada tag form_upload atribut
enctype=”multipart/form-data” harus ada. Atribut ini akan digunakan
untuk memberitahu browser dan server bahwa yang dikirim bukan hanya data nama
file, namun juga isi dari nama file.
Diperlukan juga sebuah variabel dengan nama MAX_FILE_SIZE dengan tipe
hidden, yang harus disediakan untuk mengendalikan besar file maksimum yang
diupload ke server. Variabel ini harus diletakkan sebelum input dengan type
’file’, nilai pada atribut value menunjukkan jumlah byte maksimum.
latihan 5
5. Pemrosesan
Buku Tamu dengan metode : POST
a. Untuk membuat
inputan, dan beri nama file : e.php
<html>
<head>
<title>Contoh Form dengan
POST</title>
</head>
<body>
<h1>Buku
Tamu</h1>
Komentar
dan saran sangat kami butuhkan untuk
meningkatkan
kualitas situs kami.
<hr>
<form
action="e1.php" method="post">
<pre>
Nama
anda : <input
type="text" name="nama" size="25"
maxlength="50">
Email
address : <input type="text" name="email"
size="25"
maxlength="50">
Komentar : <textarea name="komentar"
cols="40"
rows="5">
</textarea>
<input
type="submit" value="kirim">
<input type="reset"
value="ulangi">
</pre>
</form>
</body>
</html>
b. Buat file
untuk memproses variabel, beri nama filenya : e1.php
<html>
<head>
<title>Buku Tamu</title>
</head>
<body>
<?
$nama=$_POST["nama"];
$email=$_POST["email"];
$komentar=$_POST["komentar"];
?>
<h1>Data
Buku Tamu </h1>
<hr>
Nama
anda : <?echo $nama?>
<br>
Email
address : <?echo $email?>
<br>
Komentar :
<textarea
name="komentar" cols="40"
rows="5"><?echo
$komentar?> </textarea>
<br>
</body>
</html>
latihan 4
4. Perbandingan 2
bilangan menggunakan metode : POST
a. Untuk membuat
inputan, dan beri nama file : d.php
<html>
<head>
<title>Contoh Form dengan
POST</title>
</head>
<body>
<form
action="d1.php" method="post">
Bil I :
<input type="text"
name="bil1">
<br>
Bil II:
<input type="text"
name="bil2">
<br>
<input
type="submit" value="Bandingkan">
</form>
</body>
</html>
b. Buat file
untuk memproses variabel, beri nama filenya : d1.php
<html>
<head>
<title>Proses Input</title>
</head>
<body>
<?
$bil1=$_POST["bil1"];
$bil2=$_POST["bil2"];
?>
<h1>Perbandingan Bilangan </h1>
<hr>
Bil I :
<?echo $bil1?>
<br>
Bil II: <?echo $bil2?>
<br>
<?
if ($bil1<$bil2){
echo "$bil1 lebih kecil dari $bil2";
}
elseif($bil1>$bil2){
echo "$bil1 lebih besar dari $bil2";
}
else{
echo "$bil1 sama dengan $bil2";
}
?>
</body>
</html>
Langganan:
Postingan
(
Atom
)