-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
100 lines (85 loc) · 3.22 KB
/
index.php
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
<style>
body {
background-color: lightblue;
}
.hidden{
display:none;
visibility:hidden;
}
.form{
position: relative;
width: 100px;
height: 100px;
}
</style>
<form name="inscription" method="post" action="index.php">
Entrez votre nom : <h1><input type="text" name="nom"/></h1><br/>
Entrez votre prénom : <h1><input type="text" name="prénom"/></h1><br/>
Entrez votre mail : <h1><input type="text" name="mail"/></h1><br/>
Entrez votre mot de passe : <h1><input type="password" name="pw"/></h1><br/>
Entrez votre message : <h1><input type="text" name="message"/></h1><br/>
<input type="text" name="titre" class="hidden"/>
<input type="submit" name="valider" value="OK"/>
</form>
<a href="/authentification.php">authentification</a>
<?php
$pdo = null;
$dsn = 'mysql:host=localhost; dbname=base_project';
$dbUser = 'root';
$pw = 'root';
try{
$pdo = new PDO($dsn,$dbUser,$pw);
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
echo'Connection failed:' .$e->getMessage();
}
if(isset($_POST['valider'])){
if($_POST['nom'] != "" && $_POST['prénom'] != "" && $_POST['mail'] != "" && $_POST['pw'] != "" && $_POST['mail'] != ""){
if(isset($_POST['titre']) && $_POST['titre']!= ""){
die();
}
$nom = $_POST['nom'];
$prénom = $_POST['prénom'];
$mail = $_POST['mail'];
$pw = md5($_POST['pw']);
$message = $_POST['message'];
$ts= $pdo->prepare("SELECT* FROM users WHERE(Mail = '$mail')");
$ts->execute();
$nb=$ts->rowCount();
if($nb == 1){
echo "un compte existe déja avec cette adresse mail";
}elseif($nb == 0){
$sth = $pdo->prepare("
INSERT INTO users (Nom, Prenom, Mail, Pw, Message, Date, Ip)
VALUES (:nom, :prenom, :mail, :pw, :message, NOW(), :ip)
");
//$sth->bindParam(':prénom', $prénom);
$ip = $_SERVER['REMOTE_ADDR'];
$sth->bindParam(':nom', $nom);
$sth->bindParam(':prenom', $prénom);
$sth->bindParam(':mail', $mail);
$sth->bindParam(':pw', $pw);
$sth->bindParam(':message', $message);
$sth->bindParam(':ip', $ip);
$execute = $sth->execute();
if($execute == true){
header('authentification.php');
$msgSucces = "vos informations sont enregistrées avec succés cliquez sur authentification";
}else{
$msgError = "erreur d'enregistrement";
}
}
}
}
?>
<div>
<?php
if(isset($msgError)){
echo $msgError;
}
elseif(isset($msgSucces)){
echo $msgSucces;
}
?>
</div>