-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
85 lines (77 loc) · 2.4 KB
/
index.php
File metadata and controls
85 lines (77 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
$name = "";
$notes = [];
$error = "";
$sum = 0;
$moyenne = 0;
$comment = "";
if($_SERVER["REQUEST_METHOD"]== "POST"){
$name=htmlspecialchars($_POST["name"]);
$notes=$_POST["note"];
}
if(isset($_POST['submit'])){
if(empty($name) || empty($notes)){
$error="please fill it all";
}
}
if(isset($notes)&& is_array($notes)){
foreach($notes as $n){
if($n>20 || $n<0){
$error="please enter a number btween 0-20";
}
}
}
if(isset($notes)&& is_array($notes)){
foreach($notes as $n){
$sum +=$n;
}
}
$moyenne =$sum/count($notes);;
if($moyenne>=10){
$comment="Félicittaion ! vous étes admis";
}else{
$comment="maleureseument vous repasser l'exam";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>First Projet</title>
</head>
<body>
<h2></h2>
<div class="cnt">
<form method="post">
<div class="form-cnt">
<h3>name</h3>
<input type="text" class="input" name="name" id="name" required>
<h3>note 1</h3>
<input type="number" class="input" name="note[]" required>
<h3>note 2</h3>
<input type="number" class="input" name="note[]" required>
<h3>note 3</h3>
<input type="number" class="input" name="note[]" required>
<h3>note 4</h3>
<input type="number" class="input" name="note[]" required>
<h3>note 5</h3>
<input type="number" class="input" name="note[]" required>
<button type="submit" name="submit">calcul</button>
<?php if(!empty($error)): ?>
<div style="color:red;"><?=htmlspecialchars($error) ?></div>
<?php endif; ?>
</div>
</form>
<?php if ($_SERVER["REQUEST_METHOD"] == "POST" && empty($error)): ?>
<div class="result">
<h3>your name: <?= htmlspecialchars($name) ?></h3>
<!--number_format bah ndir 2 numbers mor , -->
<h3>your moyenne: <?= number_format($moyenne, 2) ?> </h3>
<p><?= htmlspecialchars($comment) ?></p>
<?php endif; ?
</div>
</div>
</body>
</html>