Kawan, kali ini saya mau melengkapi postingan tentang PHP ..
Sebelumnya saya sudah meng posting coding konversi bilangan, namun tanpa pilihan menu ..
Bimbingan : Mr. Hadi
Berikut ada lah Coding nya .. kalian harus membuat 2 file php !
selamat menyimak :)
<body>
<?php
if(isset($_POST['submit'])){//isset : penekanan form
$nama=$_REQUEST['nama'];
if(isset($_POST['gender'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
$cek='';
}
else{
$nama='';
$gender='';
$cek='Please Login :D';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
<style type="text/css">
body{
font-family:Comic sans MS;
background:yellow;
}
h2{
text-decoration:underline;
color:red;
font-weight:bold;
text-align:center;
}
</style>
</head>
<body>
<h1 class='a'>
<?php echo $cek ?></h1>
<br>
<form action="KonversiBilangan.php" method="post" name="form1">
<p>
<h3 class='b'>
Name : <input class='highlight' placeholder="" required="required" type="text" name="nama" size ="30" value="<?php echo $nama ?>"/></h3>
</p>
<p>
<h3 class='b'>
Your's Gender : <br>
<input type="radio" name="gender" value="L"
<?php ($gender=="L")? print 'checked=""' : print ''; ?>/>
Man<br>
<input type="radio" name="gender" value="P"
<?php ($gender=="P")? print 'checked=""' : print ''; ?>/>
Woman
</h3>
</p>
<input type="submit" name="submit" value="Login">
</form>
</body>
</html>
maka hasil pada browser sperti berikut :
Buat new php Web Page dengan coding :
<style type="text/css">
body
a:active{
color: blue;
}
.b{
color: #E3941D;
text-shadow:4px 0px 7px black;
font-family:AcidDreamer;
font-weight:bold;
}
body{
font-family:Comic sans MS;
background:yellow;
}
h2{
text-decoration:underline;
color:red;
font-weight:bold;
text-align:left;
}
</style>
<h1 class='b''>
Silahkan Konversikan Bilangan </h1>
<tr>
<td align ="center">
<?php
if(isset ($_POST['submit'])){
$nama=$_REQUEST['nama'];
if(isset($_POST['gender'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
}
if(isset ($_POST['submit'])){
if($nama==''|| $gender==''){// tanda || : OR
echo"<script>
alert('Maaf data kurang lengkap ? Isi Nama dan Jenis Kelamin');
document.location.href='Validator.php';
</script>";//menggunakan javascript
}
else{
}
}
?>
</td>
</tr>
</table>
<tr>
<td align ="center">
<p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>
"
method="POST" name="form1">
<h2>
Inputkan Angka Desimal : </h2>
<input class='highlight' placeholder="Input Angka" required="required" type="text" name="decimal" size ="25" value="<?php echo $decimal ?>"/><br>
<h2>
Pilih Konversi yang anda ingin kan : <br><br>
<input type="radio" name="pilih" value="B"
<?php ($pilih=="B")? print 'checked=""' : print ''; ?>/>
Bilangan Biner<br>
<input type="radio" name="pilih" value="H"
<?php ($pilih=="H")? print 'checked=""' : print ''; ?>/>
Bilangan Hexa<br>
<input type="radio" name="pilih" value="O"
<?php ($pilih=="O")? print 'checked=""' : print ''; ?>/>
Bilangan Oktal<br>
</h2>
<input type="submit" name="submit1" value="Konversikan"><br>
</form>
</head>
<body>
<!-- Proses Konversi -->
<?php
if(isset($_POST['submit1'])){//isset : penekanan form
$decimal=$_REQUEST['decimal'];
if(isset($_POST['pilih'])){
$pilih=$_REQUEST['pilih'];
}
else{
$pilih='';
}
}
else{
$decimal='';
$pilih='';
}
if(isset ($_POST['submit1'])){
if($decimal==''|| $pilih==''){
echo"<script>alert('Waw, kesalahan! Isi nilai Desimal dan pilih Konversi !!')</script>";//menggunakan javascript
}
else{
if($pilih=='B'){
//Konversi ke Biner
if (isset($_POST['decimal'])) {
$decimal = $_POST['decimal'];
$original = $_POST['decimal'];
$binary = '';
if (preg_match('/[^0-9]/',$decimal)) {
die ("Maaf. Inputan salah...");
}
else {
while ($decimal > 0) {
if ($decimal%2 == 0) {
$binary .= 0;
$decimal /= 2;
}
else {
$binary .= 1;
$decimal = ($decimal/2)-0.5;
}
}
$result = strrev($binary);
echo "<br><h2>
Bilangan decimal : $original jika dijadikan Biner hasilnya adalah $result.</h2>
";
}
}
else {
}
}
else{
if($pilih=='H'){
//Konversi ke Hexa
if(isset($_POST['decimal'])){
$des=$_POST['decimal'];
$original=$_POST['decimal'];
$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);
echo "<br><h2>
Bilangan decimal : $original jika dijadikan Hexadecimal hasilnya adalah $result.</h2>
";
}
}
else{
//Konversi ke Oktal
if(isset($_POST['decimal'])){
$des=$_POST['decimal'];
$original=$_POST['decimal'];
$octal='';
while ($des>0){
$hasil=$des%8;
switch($hasil){
case 0 : $octal.="0"; break;
case 1 : $octal.="1"; break;
case 2 : $octal.="2"; break;
case 3 : $octal.="3"; break;
case 4 : $octal.="4"; break;
case 5 : $octal.="5"; break;
case 6 : $octal.="6"; break;
case 7 : $octal.="7";
default:break;
}
if($des/8>0){
$sisa=($des/8);
$des=$sisa%8;
}
else{
$sisa=($des%8);
$des=$sisa;
}}
$result = strrev($octal);
echo "<br><h2>
Bilangan decimal : $original jika dijadikan Oktal hasilnya adalah $result.</h2>
";
}
else{
}
}
}
}
}
echo "<br><h2>
<a href='Validator.php'>RESET</a></h2>
<br><br>";
?>
<!-- End proses Konversi -->
</td>
</tr>
</table>
</body>
</html>
hasil pada browser akan tampil seperti berikut :
to Biner :
to Hexa :
to Octal :
Sebelumnya saya sudah meng posting coding konversi bilangan, namun tanpa pilihan menu ..
Bimbingan : Mr. Hadi
Berikut ada lah Coding nya .. kalian harus membuat 2 file php !
selamat menyimak :)
<body>
<?php
if(isset($_POST['submit'])){//isset : penekanan form
$nama=$_REQUEST['nama'];
if(isset($_POST['gender'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
$cek='';
}
else{
$nama='';
$gender='';
$cek='Please Login :D';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
<style type="text/css">
body{
font-family:Comic sans MS;
background:yellow;
}
h2{
text-decoration:underline;
color:red;
font-weight:bold;
text-align:center;
}
</style>
</head>
<body>
<h1 class='a'>
<?php echo $cek ?></h1>
<br>
<form action="KonversiBilangan.php" method="post" name="form1">
<p>
<h3 class='b'>
Name : <input class='highlight' placeholder="" required="required" type="text" name="nama" size ="30" value="<?php echo $nama ?>"/></h3>
</p>
<p>
<h3 class='b'>
Your's Gender : <br>
<input type="radio" name="gender" value="L"
<?php ($gender=="L")? print 'checked=""' : print ''; ?>/>
Man<br>
<input type="radio" name="gender" value="P"
<?php ($gender=="P")? print 'checked=""' : print ''; ?>/>
Woman
</h3>
</p>
<input type="submit" name="submit" value="Login">
</form>
</body>
</html>
maka hasil pada browser sperti berikut :
Buat new php Web Page dengan coding :
<style type="text/css">
body
a:active{
color: blue;
}
.b{
color: #E3941D;
text-shadow:4px 0px 7px black;
font-family:AcidDreamer;
font-weight:bold;
}
body{
font-family:Comic sans MS;
background:yellow;
}
h2{
text-decoration:underline;
color:red;
font-weight:bold;
text-align:left;
}
</style>
<h1 class='b''>
Silahkan Konversikan Bilangan </h1>
<tr>
<td align ="center">
<?php
if(isset ($_POST['submit'])){
$nama=$_REQUEST['nama'];
if(isset($_POST['gender'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
}
if(isset ($_POST['submit'])){
if($nama==''|| $gender==''){// tanda || : OR
echo"<script>
alert('Maaf data kurang lengkap ? Isi Nama dan Jenis Kelamin');
document.location.href='Validator.php';
</script>";//menggunakan javascript
}
else{
}
}
?>
</td>
</tr>
</table>
<tr>
<td align ="center">
<p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>
"
method="POST" name="form1">
<h2>
Inputkan Angka Desimal : </h2>
<input class='highlight' placeholder="Input Angka" required="required" type="text" name="decimal" size ="25" value="<?php echo $decimal ?>"/><br>
<h2>
Pilih Konversi yang anda ingin kan : <br><br>
<input type="radio" name="pilih" value="B"
<?php ($pilih=="B")? print 'checked=""' : print ''; ?>/>
Bilangan Biner<br>
<input type="radio" name="pilih" value="H"
<?php ($pilih=="H")? print 'checked=""' : print ''; ?>/>
Bilangan Hexa<br>
<input type="radio" name="pilih" value="O"
<?php ($pilih=="O")? print 'checked=""' : print ''; ?>/>
Bilangan Oktal<br>
</h2>
<input type="submit" name="submit1" value="Konversikan"><br>
</form>
</head>
<body>
<!-- Proses Konversi -->
<?php
if(isset($_POST['submit1'])){//isset : penekanan form
$decimal=$_REQUEST['decimal'];
if(isset($_POST['pilih'])){
$pilih=$_REQUEST['pilih'];
}
else{
$pilih='';
}
}
else{
$decimal='';
$pilih='';
}
if(isset ($_POST['submit1'])){
if($decimal==''|| $pilih==''){
echo"<script>alert('Waw, kesalahan! Isi nilai Desimal dan pilih Konversi !!')</script>";//menggunakan javascript
}
else{
if($pilih=='B'){
//Konversi ke Biner
if (isset($_POST['decimal'])) {
$decimal = $_POST['decimal'];
$original = $_POST['decimal'];
$binary = '';
if (preg_match('/[^0-9]/',$decimal)) {
die ("Maaf. Inputan salah...");
}
else {
while ($decimal > 0) {
if ($decimal%2 == 0) {
$binary .= 0;
$decimal /= 2;
}
else {
$binary .= 1;
$decimal = ($decimal/2)-0.5;
}
}
$result = strrev($binary);
echo "<br><h2>
Bilangan decimal : $original jika dijadikan Biner hasilnya adalah $result.</h2>
";
}
}
else {
}
}
else{
if($pilih=='H'){
//Konversi ke Hexa
if(isset($_POST['decimal'])){
$des=$_POST['decimal'];
$original=$_POST['decimal'];
$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);
echo "<br><h2>
Bilangan decimal : $original jika dijadikan Hexadecimal hasilnya adalah $result.</h2>
";
}
}
else{
//Konversi ke Oktal
if(isset($_POST['decimal'])){
$des=$_POST['decimal'];
$original=$_POST['decimal'];
$octal='';
while ($des>0){
$hasil=$des%8;
switch($hasil){
case 0 : $octal.="0"; break;
case 1 : $octal.="1"; break;
case 2 : $octal.="2"; break;
case 3 : $octal.="3"; break;
case 4 : $octal.="4"; break;
case 5 : $octal.="5"; break;
case 6 : $octal.="6"; break;
case 7 : $octal.="7";
default:break;
}
if($des/8>0){
$sisa=($des/8);
$des=$sisa%8;
}
else{
$sisa=($des%8);
$des=$sisa;
}}
$result = strrev($octal);
echo "<br><h2>
Bilangan decimal : $original jika dijadikan Oktal hasilnya adalah $result.</h2>
";
}
else{
}
}
}
}
}
echo "<br><h2>
<a href='Validator.php'>RESET</a></h2>
<br><br>";
?>
<!-- End proses Konversi -->
</td>
</tr>
</table>
</body>
</html>
hasil pada browser akan tampil seperti berikut :
to Biner :
to Hexa :
to Octal :
Comments
Post a Comment