20 Avril
This commit is contained in:
32
BACKEND/PHP/tp2/ex3/calculatrice.php
Normal file
32
BACKEND/PHP/tp2/ex3/calculatrice.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
include 'include/controller.php';
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title></title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@1.*/css/pico.min.css">
|
||||
|
||||
<link rel="stylesheet" href="./css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<h3>Calculatrice</h3>
|
||||
<form method="POST">
|
||||
<div class="grid">
|
||||
<input placeholder="un nombre" type="number" step="any" name="op1" value ="" required>
|
||||
<select name="operation" required>
|
||||
<option value="+">+</option>
|
||||
<option value="-">-</option>
|
||||
<option value="x">x</option>
|
||||
<option value="/">/</option>
|
||||
</select>
|
||||
<input placeholder="un nombre" type="number" step="any" name="op2" required>
|
||||
<button type="submit" name="soumis"> Calculer</button>
|
||||
</grid>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
6
BACKEND/PHP/tp2/ex3/css/style.css
Normal file
6
BACKEND/PHP/tp2/ex3/css/style.css
Normal file
@@ -0,0 +1,6 @@
|
||||
input[type="text"],
|
||||
select
|
||||
{
|
||||
display:inline-block;
|
||||
width:auto;
|
||||
}
|
24
BACKEND/PHP/tp2/ex3/include/controller.php
Normal file
24
BACKEND/PHP/tp2/ex3/include/controller.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
$nbr1=$_POST['op1'];
|
||||
$nbr2=$_POST['op2'];
|
||||
$ope=$_POST['operation'];
|
||||
if ($ope=="+"){
|
||||
$resultat=$nbr1+$nbr2;
|
||||
echo "<h3> Le resultat est $resultat </h3>";
|
||||
}
|
||||
if ($ope=="-"){
|
||||
$resultat=$nbr1-$nbr2;
|
||||
echo "<h3> Le resultat est $resultat </h3>";
|
||||
}
|
||||
if ($ope=="x"){
|
||||
$resultat=$nbr1*$nbr2;
|
||||
echo "<h3> Le resultat est $resultat </h3>";
|
||||
}
|
||||
if ($ope=="/"){
|
||||
if($nbr2==0){
|
||||
die("<h2> Division par 0 </h2>");
|
||||
}
|
||||
$resultat=$nbr1/$nbr2;
|
||||
echo "<h3> Le resultat est $resultat </h3>";
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user