account_creation.php
<?php
require('process/process_registration.php');
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<title>Devenir client</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div id="wrapper">
<header>
<h1>Devenir client</h1>
</header>
<div id="container">
<form method="post" action="">
<table>
<thead>
<tr>
<th>Créer un compte</th>
</tr>
</thead>
<tbody>
<tr>
<td><label for="name">Nom</label></td>
<td><input type="text" name="username_form" id="name"></td>
</tr>
<tr>
<td><label for="mail">Email</label></td>
<td><input type="text" name="usermail_form" id="mail"></td>
</tr>
</tbody>
<tfoot>
<tr>
<td><input type="submit" name="submit_form" value="Se connecter"></td>
</tr>
</tfoot>
</table>
<?php if(isset($message)) echo $message ?>
</form>
</div>
</div>
</body>
</html>
process/process_registration.php
<?php
require('class/clientManager.php');
try {
$db = new PDO('mysql:host=localhost;dbname=hotels', 'root', '10111110');
}
catch(PDOException $e) {
echo 'Erreur de connexion ' . $e->getMessage();
}
if(isset($_POST['submit_form'])) {
$username_form = trim($_POST['username_form']);
$usermail_form = trim($_POST['usermail_form']);
if((empty($username_form)) OR empty($usermail_form)) {
$message = '<p class="error">Tous les champs doivent être remplis !</p>';
}
else {
if(!filter_var($usermail_form, FILTER_VALIDATE_EMAIL)) {
$message = '<p class="error">Ce n\'est pas une adresse mail valide !</p>';
}
else {
$manager = new clientManager($db);
if($manager->getMail($usermail_form)) {
return false;
}
else {
$manager->insertClient($username_form, $usermail_form);
}
}
}
}
class/clientManager.php
<?php
class clientManager {
private $_db;
public function __construct(PDO $db) {
$this->setDb($db);
}
public function setDb($dbh) {
$this->_db = $dbh;
}
public function insertClient($name, $email) {
$sql = 'INSERT INTO client (name, email) VALUES(:name, :email)';
$stmnt = $this->_db->prepare($sql);
$stmnt->bindParam(':name', $name);
$stmnt->bindParam(':email', $email);
if($stmnt->execute()) {
echo '<p class="message">Bonjour, ' . $name . ', vous êtes nouveau client.</p>';
}
else {
echo '<p class="error">Malheuresement, l\'inscription a échouée !</p>';
}
}
public function getMail($email) {
$sql = 'SELECT COUNT(id), email FROM client WHERE email = :email';
$stmnt = $this->_db->prepare($sql);
$stmnt->execute(array(':email' => $email));
if($stmnt->fetchColumn() > 0) {
echo '<p class="error">L\'email est déjà pris !</p>';
}
else {
return true;
}
}
}
Bonjour, rien s’enregistre dans la base & aucun message d’erreur.
Merci pour votre aide.
+0
-0