Skip to content

Instantly share code, notes, and snippets.

@FreakDev
Last active August 29, 2015 14:11
Show Gist options
  • Save FreakDev/0ced2c83d9d345773b4b to your computer and use it in GitHub Desktop.
Save FreakDev/0ced2c83d9d345773b4b to your computer and use it in GitHub Desktop.
<?php
global $bdd;
try {
$bdd = new PDO("mysql:host=localhost;dbname=todo_tp;unix_socket=/home/mathiasd/.mysql/mysql.sock", "root", "root");
$bdd->exec('SET NAMES utf8');
} catch (Exception $e) {
die('Can\'t connect to MySql Serveur : ' . $e->getMessage());
}
<?php
include ('includes/bdd.php');
$message = "";
if (isset($_POST['login'])) {
$sql = "SELECT * FROM user WHERE nickname = '" . $_POST['nickname'] . "' AND password = '" . $_POST['password'] . "'";
$stmt = $bdd->prepare($sql);
$stmt->execute();
if ($stmt->rowCount() === 1) {
$dataUser = $stmt->fetch(PDO::FETCH_ASSOC);
header("Location: index.php");
exit();
} else {
$message = "Failed login";
}
}
include ('templates/login.phtml');
<?php include ('header.phtml'); ?>
<h2>Please Log in</h2>
<?php echo $message ?>
<form method="POST" action="login.php">
<label for="_nickname">Login</label><br/>
<input id="_nickname" name="nickname" type="text" value="" /><br/>
<label for="_password">Password</label><br/>
<input id="_password" name="password" type="text" value="" /><br/>
<input type="submit" name="login" value="Login">
</form>
<?php include ('footer.phtml'); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment