-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
109 lines (77 loc) · 2.4 KB
/
Copy pathtest.php
File metadata and controls
109 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
t<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
// $name="yo";
// $compteur=100 ;
// $table = ["orange" => 20 , "banane" => 30, "fraise" => 10, "mangue" => 115];
// // iftest
// // // if ($name=== "dayane") {
// // echo 'bonjour ' . $name . '<br>';}
// // else {
// // echo 'erreur' . '<br>';}
// whiletest
// // while ($compteur >= 0 ) {
// // echo 'compteur n ' . $compteur . '<br>' ;
// // $compteur= $compteur - 1 ;
// // }
// fortest
// for ($i = 1; $i <= 100; $i=$i+1 ) {
// echo $i . '<br>';
// }
// foreachtest
// foreach ($table as $fruit => $nbr) {
// echo '<strong> il y a ' . $nbr .' ' . $fruit . ' </strong><br>' ;
// }
// functiontest
// function bonjour($nom , $age) {
// echo "bonjour $nom <br>";
// $age=$age+1;
// echo "Tu auras $age ans demain";
// include 'function.php';
// }
// bonjour("dayane", 21)
// Debut test formulaire
// try{
// $user = "root";
// $pass = "";
// $dbh = new PDO('mysql:host=localhost;dbname=test', $user , $pass);
// $requete = 'SELECT * from users';
// // $result = $dbh->query($requete);
// // var_dump($result);
// foreach($dbh->query($requete) as $row) {
// affligne($row);
// }
// } catch(PDOException $e) {
// print "Erreur |: " . $e->getMessage() . "<br>";
// die();
// }
// function affligne($row) {
// echo "nom : $row[name] <br>";
// }
$name = $_POST["name"];
$pass = $_POST["pass"];
echo "bonjour $name <br>";
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
try{
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username , $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO users (name, pass) VALUES (:name, :pass)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':pass', $pass);
$stmt->execute();
header("Location: index2.html");
exit();
} catch(PDOException $e) {
print "Erreur |: " . $e->getMessage() . "<br>";
die();
}
?>
</body>
</html>