-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajouterCourse.php
More file actions
113 lines (89 loc) · 3.56 KB
/
ajouterCourse.php
File metadata and controls
113 lines (89 loc) · 3.56 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
session_start();
$ip_bloquee = '172.16.1.10';
$ip_visiteur = $_SERVER['REMOTE_ADDR'];
if ($ip_visiteur === $ip_bloquee) {
http_response_code(403);
die('Accès refusé');
}
include_once './db/variables.php';
if ($_SERVER['REQUEST_METHOD'] == "POST"){
$nom = $_POST['nom'];
$ville = $_POST['ville'];
echo "<p>la course " . $nom . " dans la ville de " . $ville . "</p>\n";
if (isset($_POST['ville']) && isset($_POST['nom'])) {
$nom = $_POST['nom'];
$ville = $_POST['ville'];
$date = $_POST['date'];
$distance = $_POST['distance'];
}
else {
echo "<p>Toutes les données doivent être renseignées.</p>\n";
}
printf("nom = %s<BR>",$nom);
printf("ville = %s\n",$ville);
printf("date = %s\n",$date);
printf("distance = %s\n",$distance);
try {
$conn = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "<p>Echec de connexion :" . $e->getMessage() ."</p>\n";
}
$conn = null;
try {
$conn = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("INSERT INTO course (cou_nom, cou_ville, cou_date, cou_distance)
VALUES (:nom, :ville, :date, :distance)");
$stmt->bindParam(':nom', $nom);
$stmt->bindParam(':ville', $ville);
$stmt->bindParam(':date', $date);
$stmt->bindParam(':distance', $distance);
$stmt->execute();
echo "<p>Insertion(s) effectée(s) : " . $stmt->rowCount() . "</p>\n";
} catch (PDOException $e) {
echo "<p>Echec de l'insertion :" . $e->getMessage() ."</p>\n";
}
$conn = null;
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="keywords" content="Course, Running">
<meta name="description" content="Devenez adhérents à des courses à pied">
<meta name="author" content="QUEIROZ Florian">
<meta name="viewport" content="width=device-width">
<title>Club de course à pied</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/pages/Connexion.css">
<link rel="stylesheet" href="css/pages/Forms.css">
<link rel="shortcut icon" href="../media/favicon.png" type="image/x-icon">
</head>
<body>
<?php
include './components/header.php';
?>
<section>
<!-- -->
<form action="/ajouterCourse.php" method="post">
<h2>Créé une nouvelle course</h2>
<label for="nom">Nom:</label>
<input name="nom" type="text" placeholder="la meilleur course au monde"><br>
<label for="ville">Ville:</label>
<input type="text" name="ville" placeholder="authon-la-plaine"><br>
<label for="distance">Distance:</label>
<input type="number" name="distance" placeholder="00"><br>
<label for="date">Date :</label>
<input type="date" id="date" name="date"><br>
<button type="submit">Ajouter</button>
<input type="reset" value="Effacer">
</form>
</section>
<?php
include './components/footer.php';
?>
</body>
</html>