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
|
<?php
class Membre {
private $pseudo;
private $password;
private $nom;
private $age;
function __construct($pseudo, $password, $nom, $age)
{
$this->pseudo = $pseudo;
$this->password = $password;
$this->nom = $nom;
$this->age = $age;
}
function Affiche()
{
echo ''.$this->pseudo.'<br />';
echo ''.$this->nom.'<br />';
echo ''.$this->age.'<br />';
}
function Add()
{
try
{
$db = new PDO('mysql:host=localhost;dbname=test', 'root', '');
}
catch(PDOException $error)
{
die("Error: " . $error->getMessage());
}
$req = $db->prepare("INSERT INTO test (pseudo, password, nom, age)VALUES(?, ?, ?, ?)");
$req->execute(array($this->pseudo, md5($this->password), $this->nom, $this->age));
}
function Connexion()
{
try
{
$db = new PDO('mysql:host=localhost;dbname=test', 'root', '');
}
catch(PDOException $error)
{
die("Error: " . $error->getMessage());
}
$req = $db->prepare("SELECT id, pseudo, nom, age FROM test WHERE pseudo = :pseudo AND password = :password");
$req->execute(array('pseudo' => $pseudo, 'password' => $password));
$resultat = $req->fetch();
if(!$resultat)
{
echo 'Mauvais password ou compte inexistant !';
}
else
{
$_SESSION['pseudo'] = $this->pseudo;
$_SESSION['nom'] = $this->nom;
$_SESSION['age'] = $this->age;
}
}
}
if(isset($_POST['submit_ins']))
{
$pseudo = htmlspecialchars($_POST['pseudo']);
$nom = htmlspecialchars($_POST['nom']);
$age = $_POST['age'];
$membre = new Membre(''.$pseudo.'', ''.$password.'', ''.$nom.'', ''.$age.'' );
$membre->Affiche();
$membre->Add();
}
if(isset($_POST['submit_co']))
{
$pseudo = htmlspecialchars($_POST['pseudo']);
$password = md5($_POST['password']);
$membre = new Membre(''.$pseudo.'', ''.$password.'', ''.$nom.'', ''.$age.'' );
$membre->Connexion();
}
?>
<form method="post" action="index.php">
<input type="text" name="pseudo" /><br />
<input type="password" name="password" /><br />
<input type="text" name="nom" /><br />
<input type="int" name="age" /><br />
<input type="submit" name="submit_ins" value="ok" /><br /><br /><br />
</form>
<form method="post" action="index.php">
<input type="text" name="pseudo" /><br />
<input type="password" name="password" /><br />
<input type="submit" name="submit_co" value="ok" /><br />
</form> |