Praktikum PHP 6
Lanjutan dari praktikum yang kemaren nih, jangan lupa di coba ya.....
- Buka Adobe Dreamweaver CS 6 atau bisa Menggunaka PHP designer 8 (sesuai selera anda)
Buat New Project -> (.php) nama project sesuai keinginan anda - Pastikan semua konfigurasi pada localhost sudah tersetting dengan siap, jangan lupa nyalakan XAMPP dan aktifkan Apache.
- Isikan Syntax di bawah ini :
<?php
session_start();
if(isset($_SESSION['error'])){
$error = $_SESSION['error'];
$true = $_SESSION['true'];
$_POST = $_SESSION['post'];
unset ($_SESSION['error']);
unset ($_SESSION['true']);
unset ($_SESSION['post']);
}
if (empty($nama) || empty($gender) || empty($email) || empty($alamat) || empty($tempat) || empty($email) || empty($pwd) || empty($agama) || empty($noHP) || empty($captcha) || empty($hari) ||empty($bualan) ||empty($bulan) ){
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="button.css" />
</head>
<body style="background-color: #0C9; background-repeat: repeat;">
<form action="action6ku.php" name="form1" method="post">
<table cellspacing="0" cellpadding="4" bgcolor="#FFFFFF" border="0" width="700" height="420" Style='border-radius:20px;border-color:white; position:fixed;left:350px;top:55px;'>
<tr>
<td rowspan="10" width="230" Style=' border-top-left-radius:20px;border-bottom-left-radius:20px ' bgcolor="white""><center><img src="a.jpg" width="200" height="200" /></center></td>
<td colspan="3" bgcolor="cyan"" Style=' border-top-right-radius:20px; '>
<center><strong><font color="white">INPUTAN BIODATA</font></strong></center>
</td>
</tr>
<tr>
<td> Nama Lengkap</td>
<td width="1"><center>:</center></td>
<td><input type='text' name="nama" size="40" placeholder="Nama Lengkap" value="<?php echo isset($_POST['nama']) ? $_POST['nama'] : ''; ?>" />
<font size="-1" color="red"><?php echo isset($error['nama']) ? $error['nama'] : '';?></font>
<font ><?php echo isset ($true['nama'])? $true['nama'] : '';?></font>
</td>
</tr>
<tr>
<td> Jenis Kelamin</td>
<td><center>:</center></td>
<td>
<input type="radio" name="gender" value="<?php echo isset($_POST['gender']) ? $_POST['gender'] : ''; ?>Laki - Laki <?php echo isset($_POST['gender']) ? ' checked' : ''; ?>"/> Laki-Laki
<input type="radio" name=gender value="<?php echo isset($_POST['gender']) ? $_POST['gender'] : ''; ?> Perempuan <?php echo isset($_POST['gender']) ? ' checked' : ''; ?>" /> Perempuan
<font size="-1" color="red"><?php echo isset($error['gender']) ? $error['gender'] : '';?></font>
<?php echo isset ($true['gender'])? $true['gender'] : '';?> </td>
</tr>
<tr>
<td>TTL</td>
<td><center>:</center></td>
<td> <input type='text' placeholder="Tempat" name="tempat" size="4" value="<?php echo isset($_POST['tempat']) ? $_POST['tempat'] : ''; ?>" />
<font size="-1" color="red"><?php echo isset($error['tempat']) ? $error['tempat'] : '';?></font>
<font ><?php echo isset ($true['tempat'])? $true['tempat'] : '';?></font>
<?php
$bulan=array("Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember");
//membuat combo box hari
echo '<select name="hari">';
$hari=1;
while($hari<=31){
echo "<option value=\"$hari\">$hari</option>";
$hari++;
}
echo '</select>';
//membuat combo box bulan
echo '<select name="bulan">';
$jumlah=count($bulan);
for ($i=0; $i<$jumlah ; $i++){
echo '<option value="'.$bulan[$i].'">'.$bulan[$i].'</option>';
}
echo'</select>';
//membuat combo box tahun
echo '<select name="tahun">';
for($tahun=1990; $tahun<2001; $tahun++){
echo"<option value=\"$tahun\">$tahun</option>";
}
echo '</select>';
?>
</td>
</tr>
<tr>
<td>Alamat</td>
<td><center>:</center></td>
<td><input type='text' placeholder="Alamat" name="alamat" size="40" value="<?php echo isset($_POST['alamat']) ? $_POST['alamat'] : ''; ?>" />
<font size="-1" color="red"><?php echo isset($error['alamat']) ? $error['alamat'] : '';?></font>
<font ><?php echo isset ($true['alamat'])? $true['alamat'] : '';?></font></td>
</tr>
<tr>
<td>E-mail</td>
<td><center>:</center></td>
<td><input type='text' name="email" placeholder="E-mail" size="40" value="<?php echo isset($_POST['email']) ? $_POST['email'] : ''; ?>" />
<font size="-1" color="red"><?php echo isset($error['email']) ? $error['email'] : '';?></font>
<font ><?php echo isset ($true['email'])? $true['email'] : '';?></font> </td>
</tr>
<tr>
<td>Password</td>
<td><center>:</center></td>
<td><input type='password' placeholder="Password" name="pwd" size="40" value="<?php echo isset($_POST['pwd']) ? $_POST['pwd'] : ''; ?>" />
<font size="-1" color="red"><?php echo isset($error['pwd']) ? $error['pwd'] : '';?></font>
<font ><?php echo isset ($true['pwd'])? $true['pwd'] : '';?></font> </td>
</tr>
<tr>
<td>No. HP</td>
<td><center>:</center></td>
<td><input type='text' placeholder="No.HP" name="HP" size="40" value="<?php echo isset($_POST['HP']) ? $_POST['HP'] : ''; ?>" />
<font size="-1" color="red"><?php echo isset($error['HP']) ? $error['HP'] : '';?></font>
<font ><?php echo isset ($true['HP'])? $true['HP'] : '';?></font> </td>
</tr>
<tr>
<td>Captcha <img height="30" style="vertical-align:middle;" src="captchaku.php?data=<?php echo date('YmdHis');?> alt="securiy image" /></td>
<td><center>:</center></td>
<td> <input name="pin" placeholder="Captcha" type="text" value="<?php echo isset($_POST['captcha']) ? $_POST['captcha'] : ''; ?>" />
<font size="-1" color="red"><?php echo isset($error['pin']) ? $error['pin'] : '';?></font>
<font ><?php echo isset ($true['pin'])? $true['pin'] : '';?></font> </td>
</tr>
<tr>
<td colspan="3" Style=' border-bottom-right-radius:20px;'><center><button type="reset" value="Refresh" ONCLICK="history.go(0)"> Reset </button>
<button type="submit" name="submit"> Kirim </button></center></td>
</tr>
</table>
</form>
<?php } ?>
</body>
</html>
screenshootnya : - Tekan F12
- Buat New Project Lagi -> (.php) nama project sesuai keinginan anda
- Isikan Syntax di bawah ini :
<?php
session_start();
if ($_POST) {
$nama = $_POST['nama'];
$gender = isset($_POST['gender']) ? $_POST['gender'] : "";
$tempat = $_POST['tempat'];
$hari = $_POST['hari'];
$bulan = $_POST['bulan'];
$tahun = $_POST['tahun'];
$alamat = $_POST['alamat'];
$email = $_POST['email'];
$pwd = $_POST['pwd'];
$noHP = $_POST['HP'];
$CAPTCHA = $_POST['pin'];
$emailpattern = '/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/';
$imgTrue = '<img src="images/true.png" style="vertical-align:middle"/><br>';
$imgEmp = '<img src="images/empty.png" style="vertical-align:middle"/><br>';
$imgErr = '<img src="images/error.png" style="vertical-align:middle"/><br>';
$error = array();
if (empty($nama)) {
$error['nama'] = $imgEmp . 'Nama harus diisi';
} else if (preg_match('/[^a-zA-Z ]/', $nama)) {
$error['nama'] = $imgErr . 'Nama hanya mengandung huruf saja';
} else {
$true['nama'] = $imgTrue;
} if (empty($email)) {
$error['email'] = $imgEmp . 'Email harus diisi';
} elseif (!preg_match($emailpattern, $email)) {
$error['email'] = $imgErr . 'Email salah tulis (xxxxxxx@xxxxx.xxx)';
} else {
$true['email'] = $imgTrue;
} if (empty($alamat)) {
$error['alamat'] = $imgEmp . 'Alamat harus diisi';
} else {
$true['alamat'] = $imgTrue;
} if (empty($pwd)) {
$error['pwd'] = $imgEmp . 'Password harus diisi';
} else {
$true['pwd'] = $imgTrue;
} if (empty($gender)) {
$error['gender'] = $imgEmp . 'Jenis kelamin harus diisi';
} else {
$true['gender'] = $imgTrue;
} if (empty($tempat)) {
$error['tempat'] = $imgEmp . 'TTL harus diisi';
} else {
$true['tempat'] = $imgTrue;
} if (empty($noHP)) {
$error['HP'] = $imgEmp . 'No HP harus diisi';
} else if (preg_match('/[^0-9 ]/', $noHP)) {
$error['HP'] = $imgErr . 'No HP hanya mengandung angka aja';
} else {
$true['HP'] = $imgTrue;
} if (empty($CAPTCHA)) {
$error['pin'] = $imgEmp . 'Captcha harus diisi';
} elseif (md5($_POST['pin']) <> $_SESSION['image_random_value']) {
$error['pin'] = $imgErr . 'Maaf ,Anda bukan manusia';
} else {
$true['pin'] = $imgTrue;
} if (empty($error)) {
if ($gender == 'Laki-Laki') {
echo'<h2><center>Selamat Datang Saudara, ' . $nama . '<br>Ini adalah Data diri Anda</center></h2>';
} else {
echo'<h2><center>Selamat Datang Saudari, ' . $nama . '<br>Ini adalah Data diri Anda</center></h2>';
} print(" <table cellspacing='0' cellpadding='4' bgcolor='#FFFFFF' border='1' width='650' height='300' Style='border-radius:20px;border-color:white; position:fixed;left:360px;top:110px;box-shadow: 0 0 5px 5px black; '> <tr> <td colspan='4' background='f.jpg' Style=' border-top-left-radius:20px; border-top-right-radius:20px'> <center><strong><font color='white'><div class='Da'>DATA DIRI</div></font></strong></center> </td> </tr> <tr> <td> Nama Lengkap </td> <td width='1'><center>:</center></td> <td> $nama</td> </tr> <tr> <td> Jenis Kelamin</td> <td><center>:</center></td> <td> $gender </td> </tr> <tr> <td>TTL</td> <td><center>:</center></td> <td>$tempat, $hari - $bulan - $tahun</td> </tr> <tr> <td>Alamat</td> <td><center>:</center></td> <td> $alamat</td> </tr> <tr> <td>E-mail</td> <td><center>:</center></td> <td>$email</td> </tr> <tr> <td>Password</td> <td><center>:</center></td> <td> $pwd</td> </tr> <tr> <td Style=' border-bottom-left-radius:20px'>No. HP</td> <td><center>:</center></td> <td>$noHP</td> </tr> <tr> </table> ");
} else {
$_SESSION['error'] = $error;
$_SESSION['true'] = $true;
$_SESSION['post'] = $_POST;
header("location:tugas6ku.php");
}
} ?>
screenshootnya : - Kemudian tekan F12
- Maka Hasilnya akan seperti ini :
- Selamat mencoba :D
Komentar
Posting Komentar