Created
June 2, 2016 07:08
-
-
Save vuthaihoc/b76077bbd1f92810bdca23c532642c18 to your computer and use it in GitHub Desktop.
Bài 6 của HoanNC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: text/html; charset=utf-8'); | |
$value1 = isset($_POST['value1']) ? $_POST['value1'] : ''; | |
$value2 = isset($_POST['value2']) ? $_POST['value2'] : ''; | |
$result = 0; | |
$msg = ""; | |
if(isset($_POST)){ | |
if(is_numeric($value1) && is_numeric($value2)){ | |
if(isset($_POST['add'])){ | |
$result = $value1 + $value2; | |
} | |
elseif(isset($_POST['sub'])){ | |
$result = $value1 - $value2; | |
} | |
elseif(isset($_POST['multi'])){ | |
$result = $value1 * $value2; | |
} | |
elseif(isset($_POST['divi'])){ | |
$result = $value1 / $value2; | |
} | |
elseif(isset($_POST['pow'])){ | |
$result = pow($value1, $value2); | |
} | |
$msg = '<b>Kết quả</b>'; | |
$msg .= '<input type = "text" readonly value = "'.$result.'" placeholder="Kết quả">'; | |
}else{ | |
$msg = '<label style = "color: red">Bạn đã nhập sai ! Vui lòng nhập lại !</label>'; | |
} | |
} | |
?> | |
<h1> Bài 6: Máy tính điện tử </h1> | |
<form action = "" method = "post"> | |
<input type = "text" name = "value1" placeholder="Giá trị 1" value="<?php echo $value1; ?>"> | |
<input type = "submit" value = "+" name = "add"> | |
<input type = "submit" value = "-" name = "sub"> | |
<input type = "submit" value = "x" name = "multi"> | |
<input type = "submit" value = "/" name = "divi"> | |
<input type = "submit" value = "^" name = "pow"> | |
<input type = "text" name = "value2" placeholder="Giá trị 2" value="<?php echo $value2; ?>"> | |
</form> | |
<?php echo $msg; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment