Sekarang saya akan memposting tentang Praktikum PHP 6
1. Buka Dreamweaver CS6
2. Buat New File dengan nama form.php
3. Ketiikkan script di bawah :
4. Buat New File lagi dengan nama form_tampil.php
5. Ketikkan script di bawah ini :
6. Maka hasilnya akan tampak seperti gambar di bawah ini
Terima Kasih
1. Buka Dreamweaver CS6
2. Buat New File dengan nama form.php
3. Ketiikkan script di bawah :
<?php
session_start();
if(isset($_SESSION['error']))
{
$error
= $_SESSION['error'];
$_POST
= $_SESSION['post'];
unset($_SESSION['error']);
unset($_SESSION['post']);
}
if(empty($namaLengkap)
|| empty($nama) || empty($gender) || empty($ttl) || empty($hari) ||
empty($bulan) || empty($tahun)|| empty($email)
||
empty($pass)|| empty($alamat) || empty($hp) || empty($pin)) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
img {
margin: 25px;
opacity:0.5;
}
img:hover {
opacity:1;
}
</style>
</head>
<body
style="background-color:#000000">
<form name="form-name"
method="post" action="form_tampil.php">
<table
width="65%"
border="0" align="center" bgcolor="#CCCCCC"
class="img"
style='border-radius:25px;
border-color:#09F; box-shadow:0 0 5px 5px #03F; top:80px; left:280px;' >
<tr>
<td rowspan="11"
width="15%" style="border-top-left-radius:25px;
border-color:transparent; border-bottom-left-radius:25px" >
<center>
<img style="border-radius:25px;;"
src="logotelkom.jpg" width="200" height="300"
/> </center>
</td>
<td colspan="3" bgcolor="#CCCCCC"
style="border-top-right-radius:25px;">
<center><strong><font color="#000099"
size="+2">INPUTAN BIODATA<br /></font>
<font color="#0000CC" face="Lucida Sans Unicode"
size="-3">
</font></strong></center>
</td>
</tr>
<tr>
<td
width="22%"><font face="Lucida Sans Unicode"
size="2">Nama Lengkap</font></td>
<td width="3%"><center>:</center></td>
<td width="40%"><input name="namaLengkap"
id="namaLengkap" type="text" size="31"
value="<?php echo isset($_POST['namaLengkap']) ?
$_POST['namaLengkap'] : ''; ?>" />
<font color=blue><?php echo isset($error['namaLengkap']) ?
$error['namaLengkap'] : ''; ?></font>
</td>
</tr>
<tr>
<td><font face="Lucida
Sans Unicode" size="2">Nama</font></td>
<td><center>:</center></td>
<td><input name="nama" id="nama"
type="text" size="31"
value="<?php echo isset($_POST['nama']) ? $_POST['nama'] : '';
?>" />
<font color=blue><?php echo isset($error['nama']) ?
$error['nama'] : ''; ?></font></td>
</tr>
<tr>
<td><font face="Lucida
Sans Unicode" size="2">Jenis Kelamin</font></td>
<td><center>:</center></td>
<td><input type="radio" name="gender"
value="L" <?php echo $_POST['gender']=="L" ? 'checked' :
''; ?> />Laki-Laki
<input type="radio" name="gender"
value="P" <?php echo $_POST['gender']=="P" ? 'checked' :
''; ?> />Perempuan
<font color=blue><?php echo isset($error['gender']) ?
$error['gender'] : ''; ?></font>
</td>
</tr>
<tr>
<td><font face="Lucida
Sans Unicode" size="2">TTL</font></td>
<td><center>:</center></td>
<td><input name="ttl" id="ttl"
type="text" size="31"
value="<?php echo isset($_POST['ttl']) ? $_POST['ttl'] : '';
?>" />
<font color=blue><?php echo isset($error['ttl']) ?
$error['ttl'] : ''; ?></font>
<br />
<?php
$bulan = array ("Januari",
"Februari", "Maret", "April",
"Mei",
"Juni", "Juli", "Agustus", "September",
"Oktober",
"November", "Desember");
echo'<select name="hari">';
echo "<option
value=hari>Hari</option>";
$hari=1;
$haripilih = isset($_POST['hari']) ?
$_POST['hari'] : "hari";
while($hari<=31)
{
echo
"<option value=$hari";
echo
$hari ==$haripilih ? " selected" : "";
echo
'>'.$hari.'</option>';
$hari++;
}
echo '</select>';
echo '<select name="bulan">';
echo "<option value=bulan>Bulan</option>";
$jumlah=count($bulan);
$bulanpilih = isset($_POST['bulan']) ?
$_POST['bulan'] : "bulan";
for ($i=0; $i<$jumlah; $i++)
{
echo
"<option value=$bulan[$i]";
echo
$bulan[$i] == $bulanpilih ? " selected" : "";
echo
'>'.$bulan[$i].'</option>';
}
echo '</select>';
echo '<select name="tahun">';
echo "<option
value=tahun>Tahun</option>";
$tahunpilih = isset($_POST['tahun']) ?
$_POST['tahun'] : "tahun";
for($tahun=1985; $tahun<1999; $tahun++)
{
echo
"<option value='$tahun'";
echo
$tahun == $tahunpilih ? " selected" : "";
echo
'>'.$tahun.'</option>';
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td><font face="Lucida
Sans Unicode" size="2">Email</font></td>
<td><center>:</center></td>
<td><input name="email" id="email"
type="text" size="31"
value="<?php echo isset($_POST['email']) ? $_POST['email'] : '';
?>" />
<font color=blue><?php echo isset($error['email']) ?
$error['email'] : ''; ?>
</tr>
<tr>
<td><font face="Lucida
Sans Unicode" size="2">Password</font></td>
<td><center>:</center></td>
<td><input name="pass" id="pass"
type="password" size="31"
value="<?php echo isset($_POST['pass']) ? $_POST['pass'] : '';
?>" />
<font color=blue><?php echo isset($error['pass']) ?
$error['pass'] : ''; ?></font></td>
</tr>
<tr>
<td><font face="Lucida
Sans Unicode" size="2">Alamat</font></td>
<td><center>:</center></td>
<td><input name="alamat" id="alamat"
type="text" size="31"
value="<?php echo isset($_POST['alamat']) ? $_POST['alamat'] :
''; ?>" />
<font color=blue><?php echo isset($error['alamat']) ?
$error['alamat'] : ''; ?></font></td>
</tr>
<tr>
<td><font face="Lucida
Sans Unicode" size="2">No. HP</font></td>
<td><center>:</center></td>
<td><input name="hp" id="hp"
type="text" size="31"
value="<?php echo isset($_POST['hp']) ? $_POST['hp'] : '';
?>" />
<font color=blue><?php echo isset($error['hp']) ? $error['hp']
: ''; ?></font></td>
</tr>
<tr>
<td><font face="Lucida
Sans Unicode" size="2">Captcha <img
style="vertical-align:middle;
opacity:1; "
src="captcha.php?date=<?php echo date('YmdHis');?>"
alt="security image" /></font></td>
<td><center>:</center></td>
<td><input type="text" name="pin"
size="31"
value="<?php echo isset($_POST['pin']) ? $_POST['pin'] : '';
?>" />
<font color=blue><?php echo isset($error['pin']) ?
$error['pin'] : ''; ?></font></td>
</tr>
<tr><td colspan="4"
style="border-bottom-right-radius:25px">
<center><input name="PRINT" id="submit"
type="Submit" value="Submit"
style="background-color:#00F; border-radius:15px" />
<button type="reset" value="Refresh"
onclick="history.go(0)" style="background-color:#00F;
border-radius:15px" > Reset </button>
</center></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
4. Buat New File lagi dengan nama form_tampil.php
5. Ketikkan script di bawah ini :
<?php
session_start();
if ($_POST)
{
$namaLegkap
=$_POST['namaLengkap'];
$nama
=$_POST['nama'];
$gender
=isset($_POST['gender'])? $_POST['gender'] : "";
$ttl
=$_POST['ttl'];
$hari
=$_POST['hari'];
$bulan
=$_POST['bulan'];
$tahun
=$_POST['tahun'];
$email
=$_POST['email'];
$pass
=$_POST['pass'];
$alamat
=$_POST['alamat'];
$hp
=$_POST['hp'];
$pin
=$_POST['pin'];
$emailpattern
= '/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/';
$imgErr='<img
src=del_img.png
style="vertical-align:middle;
opacity:1;"
/><br>';
$imgEmm='<img
src=pencil2.png
style="vertical-align:middle;
opacity:1;"
/><br>';
$namaPattern
= '/[^0-9]/';
$hpPattern
= '/[^a-zA-Z]/';
$error
=array();
if(empty($namaLegkap))
{
$error['namaLengkap']
= $imgEmm.'<font face="Lucida Sans Unicode"
size="2">Nama Tidak Boleh Kosong</font>';
}
else
if(!preg_match($namaPattern, $namaLegkap))
{
$error['namaLengkap']
= $imgErr.'<font face="Lucida Sans Unicode"
size="2">Nama hanya dapat diisi huruf</font>';
}
if(empty($nama))
{
$error['nama']
= $imgEmm.'<font face="Lucida Sans Unicode"
size="2">Nama Tidak Boleh Kosong</font>';
}
elseif(!preg_match($namaPattern,
$nama))
{
$error['nama']
= $imgErr.'<font face="Lucida Sans Unicode"
size="2">Nama hanya dapat diisi huruf</font>';
}
if(empty($gender))
{
$error['gender']
= $imgEmm.'<font face="Lucida Sans Unicode"
size="2">Tentukan gender anda</font>';
}
else
{
$true['gender']
=$imgTrue;
}
if(empty($ttl))
{
$error['ttl']
= $imgEmm.'<font face="Lucida Sans Unicode"
size="2">TTl Tidak Boleh Kosong</font>';
}
if(empty($email))
{
$error['email']
= $imgEmm.'<font face="Lucida Sans Unicode"
size="2">Email Tidak Boleh Kosong</font>';
}
elseif(!preg_match($emailpattern,
$email))
{
$error['email']
= $imgErr.'<font face="Lucida Sans Unicode"
size="2">Email Salah Penulisan (xxxxxx@xxxx.xxx)</font>';
}
if(empty($pass))
{
$error['pass']
= $imgEmm.'<font face="Lucida Sans Unicode"
size="2">Pass anda harus tertera</font>';
}
if(empty($alamat))
{
$error['alamat']
= $imgEmm.'<font face="Lucida Sans Unicode"
size="2">Alamat Tidak Boleh Kosong</font>';
}
if(empty($hp))
{
$error['hp']
= $imgEmm.'<font face="Lucida Sans Unicode"
size="2">No. Hp Tidak Boleh Kosong</font>';
}
elseif(!preg_match($hpPattern,
$hp))
{
$error['hp']
= $imgErr.'<font face="Lucida Sans Unicode"
size="2">Hanya masukkan angka</font>';
}
if(empty($pin))
{
$error['pin']
= $imgEmm.'<font face="Lucida Sans Unicode"
size="2">Captcha Tidak Boleh Kosong</font>';
}
elseif(md5($_POST['pin'])
!= $_SESSION['image_random_value'])
{
$error['pin']
= $imgErr.'<font face="Lucida Sans Unicode"
size="2">Captcha Salah</font>';
}
if
(empty($error))
{
echo
"<center><font face='Book Antiqua' color='#FFFFFF'
size='+3'>Terima Kasih Sudah Mengisi Semua
Inputan</font></center> <br> ";
if($gender=='L')
{
echo
"<center><font face='Book Antiqua' color='#FFFFFF'
size='+2'>Selamat Datang Saudara,
$namaLegkap</font></center>";
echo
"<br /><br />";
}
else
{
echo
"<center><font face='Book Antiqua' color='#FFFFFF'
size='+2'>Selamat Datang Saudari, $namaLegkap</font></center>";
echo
"<br /><br />";
}
print("
<table
width='50%' border='3' align='center'
cellspacing='0' bgcolor='#FFFFFF' class='img'
style='border-radius:25px;
border-color:Blue; box-shadow:0 0 5px 5px Blue; top:80px; left:280px;' >
<tr>
<td rowspan='11' width='15%'
style='border-top-left-radius:25px; border-color:transparent;
border-bottom-left-radius:25px' >
<center><img style='border-radius:25px;' src='logotelkom.jpg'
width='200' height='200' /></center>
</td>
<td colspan='3' bgcolor='#6633CC'
style='border-top-right-radius:25px;'>
<center><strong><font color=#FFFFFF>Inilah Biodata
Anda<br /></font>
<font color=#00FFFF face='Lucida Sans Unicode' size='-3'>Data Yang
Anda Isikan Adalah Sebagai Berikut
</font></strong></center>
</td>
</tr>
<tr>
<td width='22%'><font
face='Lucida Sans Unicode' size='2'>Nama Lengkap</font></td>
<td width='3%'><center>:</center></td>
<td width='25%'> $namaLegkap </td>
</tr>
<tr>
<td><font face='Lucida Sans
Unicode' size='2'>Nama</font></td>
<td><center>:</center></td>
<td> $nama </td>
</tr>
<tr>
<td><font face='Lucida Sans
Unicode' size='2'>Jenis Kelamin</font></td>
<td><center>:</center></td>
<td> $gender </td>
</tr>
<tr>
<td><font face='Lucida Sans
Unicode' size='2'>TTL</font></td>
<td><center>:</center></td>
<td> $ttl, $hari $bulan $tahun </td>
</tr>
<tr>
<td><font face='Lucida Sans
Unicode' size='2'>Email</font></td>
<td><center>:</center></td>
<td> $email </td>
</tr>
<tr>
<td><font face='Lucida Sans
Unicode' size='2'>Password</font></td>
<td><center>:</center></td>
<td> $pass </td>
</tr>
<tr>
<td><font face='Lucida Sans
Unicode' size='2'>Alamat</font></td>
<td><center>:</center></td>
<td> $alamat </td>
</tr>
<tr>
<td><font face='Lucida Sans
Unicode' size='2'>No. HP</font></td>
<td><center>:</center></td>
<td> $hp </td>
</table>
");
}
else
{
$_SESSION['error']
=$error;
$_SESSION['post']
= $_POST;
header("location:
form.php");
}
}
?>
<body
style="background-color:#000000">
<br /><br />
<center>
<?php echo
"<br/><br/><a href='form.php'><img width='80px'
height='65px' src='BACK 2.gif'></a>"; ?>
</center>
6. Maka hasilnya akan tampak seperti gambar di bawah ini
Terima Kasih