<?php
if(isset($_POST['submit'])){
$nama=$_REQUEST['nama'];
if(isset($_POST['gender'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
$cek='';
}
else{
$nama='';
$gender='';
$cek="diisi dengan lengkap :)!";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<style type="text/css">
#form-wrap {
background-image:url(11.jpg);
}
#lala{
width: 500px;
height: 200;
margin: 80px auto;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
background: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0, rgb(113,189,123,71)),
color-stop(0.41, rgb(200,168,98,87)),
color-stop(1, rgb(124,112,118,165))
);
background: -moz-linear-gradient(
center bottom,
rgb(255,255,255) 0%,
rgb(217,217,217) 50%,
rgb(255,255,255) 100%
);
}
#submit {
width: 100px;
cursor: pointer;
box-shadow: 0 0 4px 0 #f9f82b;
-moz-box-shadow: 0 0 4px 0 #f9f82b;
-webkit-box-shadow: 0 0 4px 0 #f9f82b;
background: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0, rgb(237,237,237)),
color-stop(0.41, rgb(217,217,217)),
color-stop(1, rgb(255,255,255))
);
background: -moz-linear-gradient(
center bottom,
rgb(237,237,237) 0%,
rgb(217,217,217) 50%,
rgb(255,255,255) 100%
);
}
#submit:hover {
background: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0, rgb(456,121,179)),
color-stop(0.50, rgb(130,51,112)),
color-stop(1, rgb(118,125,200))
);
background: -moz-linear-gradient(
center bottom,
rgb(456,121,179) 0%,
rgb(130,51,112) 50%,
rgb(118,125,200) 100%
);
}
</style>
<script language="JavaScript">
window.alert("Selamat datang");
</script>
</head>
<body id="form-wrap">
<center>
<font face="Franklin Gothic ..." color="#f9f82b" size="6"><b><h1>
<?php echo $cek ?></h1>
</b></br></font></center>
<form action="yangbaru.php" method="post" name="form1" id="lala" >
<font face="Franklin Gothic ..." size="4"><p>
Nama : <input type="text" placeholder="nama" name="nama" value=" <?php echo $nama ?>"/></p>
<p>
Jenis Kelamin : <br><input type="radio" name="gender" value="L"
<?php ($gender=="L")? print 'checked=""': print ''; ?>/>
Laki-Laki<br>
<input type="radio" name="gender" value="p"
<?php ($gender=="P")? print 'checked=""': print ''; ?> />
Perempuan</p>
<center>
<input type="submit" name="Lanjut" value="Submit" id="submit"/></center>
</font>
</form>
<?php
if(isset($_POST['submit'])){ //apakah data ter-submit?
/*membuat variabel untuk menyimpan data yan dikirim*/
$nama=$_REQUEST['nama'];
if(isset($_POST['gender'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
//cek apakah data yang dikirim tidak kosong
if($nama=='' || $gender==''){
echo '<h2>
(Maaf Data Kurang Lengkap);</h2>
';
}else{
/*cek jenis kelamin*/
if($gender=='L'){
echo '<h2>
Selamat Datang Bro, '.$nama.' !!</h2>
';
}else{
echo '<h2>
Selamat Datang Sis, '.$nama.' !!</h2>
';
}
}
}
?>
</body>
</html>
SETELAH ITU KITA BUAT PROJECT BARU :
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
error_reporting(0);
$des = $_REQUEST['des'];//deklarasi var desimal
$option = $_REQUEST['option'];//deklarasi var pilihan
//Membuat function bin untuk konversi ke biner
function bin($bil){
$decimal= $bil;
$ori=$decimal;;
while ($decimal>0){ //Looping memutuskan apakah inputan 1 atau 0 yang ditampilkan
if($decimal%2 == 0){ // menampbah 0
$binary .= 0; //$binary=0+$binary
$decimal /= 2; //$decimal=$decimal/2
}
else{ //menambah 1
$binary .= 1; //$binary=1+$binary
$decimal = ($decimal/2)-0.5;
}
}
$result = strrev($binary);
return "Biner dari : $ori adalah : $result <br/>"; //funngsi ini mereturn hasil
}
//Membuat function oct untuk konversi ke octal
function oct($bil){
$des= $bil;
$ori=$des;
$oct='';
while($des>0){
$hasil=$des%8;
switch($hasil){
case 0: $oct.="0"; break;
case 1: $oct.="1"; break;
case 2: $oct.="2"; break;
case 3: $oct.="3"; break;
case 4: $oct.="4"; break;
case 5: $oct.="5"; break;
case 6: $oct.="6"; break;
case 7: $oct.="7"; break;
default : break;
}
if($des/8==0){
$sisa=($des%8);
$des=$sisa;
}
else{
$sisa=($des/8);
$des=$sisa%8;
}
}
$result = strrev($oct);
return "Octal dari : $ori adalah : $result <br/>"; //funngsi ini mereturn hasil
}
//Membuat function hex untuk konversi ke hexa
function hex($bil){
$des= $bil;
$ori=$des;
$hex='';
while($des>0){
$hasil=$des%16;
switch($hasil){
case 0: $hex.="0"; break;
case 1: $hex.="1"; break;
case 2: $hex.="2"; break;
case 3: $hex.="3"; break;
case 4: $hex.="4"; break;
case 5: $hex.="5"; break;
case 6: $hex.="6"; break;
case 7: $hex.="7"; break;
case 8: $hex.="8"; break;
case 9: $hex.="9"; break;
case 10: $hex.="A"; break;
case 11: $hex.="B"; break;
case 12: $hex.="C"; break;
case 13: $hex.="D"; break;
case 14: $hex.="E"; break;
case 15: $hex.="F";
default : break;
}
if($des/16==0){
$sisa=($des%16);
$des=$sisa;
}
else{
$sisa=($des/16);
$des=$sisa%16;
}
}
$result = strrev($hex);
return "Hexa dari : $ori adalah : $result <br/>"; //funngsi ini mereturn hasil
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Converter Option for Biner by Firayz</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="post" name="form1">
<p>Inputkan bilangan desimal :
<input type="text" name="des" value="<?php echo $des ?>" /></p>
<p>Pilih konversi : <br/>
<input type="radio" name="option" value="bin"
<?php ($option=="bin") ? print 'checked=""': print ''; ?>/>
Desimal to Biner<br/>
<input type="radio" name="option" value="hex"
<?php ($option=="hex") ? print 'checked=""': print ''; ?>/>
Desimal to Hexa<br/>
<input type="radio" name="option" value="oct"
<?php ($option=="oct") ? print 'checked=""': print ''; ?>/>
Desimal to Octal<br/>
</p>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
if(isset($_POST['des'])){ //apakah data tersubmit?
/*mambuat variable untuk menyimpan data yang dikirim*/
$des = $_REQUEST['des'];
$option = $_REQUEST['option'];
//cek apakah data yang dikirim tidak kosong ?
if($des=='' || $option==''){
echo '<h2>Maaf data Kurang Lengkap</h2>';
}
else{
//cek jenis kelamin
switch($option){
case 'bin' : echo "<h3>".bin($des)."</h3>"; break;
case 'hex' : echo "<h3>".hex($des)."</h3>"; break;
case 'oct' : echo "<h3>".oct($des)."</h3>"; break;
default : break;
}
}
echo "<a href='".$_SERVER['PHP_SELF']."'>Reset</a>"; //hasil
}
?>
</body>
</html>
- biner
hexa
octal
semoga bermanfaat ^^
Tidak ada komentar:
Posting Komentar