-
-
Save 2Fwebd/d51faeee349aeee9419a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* PLAN | |
* 1) On se connecte à la base de données | |
* 2) On check si le forumlaire a été envoyé | |
* - On verifie si il existe dans le BDD sinon on créé une variable d'erreur | |
* 3) On commence le HTML | |
* 4) Menu et classes qui vous servent a rien | |
* 5) On affiche une erreur ou le nom | |
* 6) On affiche le formulaire qui dirige vers la MEME page | |
* | |
*/ | |
// Database Connect : | |
$connect = mysqli_connect("localhost", "root", "root", "iteem"); | |
if (!$connect) { | |
echo "Error: Unable to connect to MySQL."; | |
echo "Debugging errno: " . mysqli_connect_errno(); | |
echo "Debugging error: " . mysqli_connect_error(); | |
exit; | |
} | |
// Variable qui check si y'a une erreur : | |
$loggin_error = 0; | |
// si le form est submitted : | |
if (!empty($_POST['login'])) { | |
// On récupére les values, on vérifie si elles sont vides sinon ça devient '' : | |
$login = (isset($_POST['login'])) ? $_POST['login'] : ''; | |
$password = (isset($_POST['password'])) ? $_POST['password'] : ''; | |
// Si il y'a un mot de passe ET un login : | |
if (!empty($login) && !empty($password)) { | |
// on fait la Query dans la base de donnees : | |
$sql = "SELECT * FROM users WHERE login LIKE '$login' AND pswd LIKE '$password'"; | |
// We fetch the result | |
$result = mysqli_query($connect, $sql); | |
// Si y'a un match | |
if($result->num_rows != 0){ | |
// On en fait un tableau | |
$connected_user = mysqli_fetch_assoc($result); | |
} | |
else { | |
// erreur n°2 pas d'user | |
$loggin_error = 2; | |
} | |
} | |
else { | |
// erreur n°1 pas de password envoyé | |
$loggin_error = 1; | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Iteem IE2</title> | |
<!-- Bootstrap core CSS --> | |
<link href="assets/css/bootstrap.min.css" rel="stylesheet"> | |
<link href="assets/css/style.css" rel="stylesheet"> | |
</head> | |
<body> | |
<nav class="navbar navbar-inverse navbar-fixed-top"> | |
<div class="container"> | |
<div class="navbar-header"> | |
<a class="navbar-brand" href="index.html">Iteem IE2</a> | |
</div> | |
<div id="navbar" class="collapse navbar-collapse"> | |
<ul class="nav navbar-nav"> | |
<li><a href="index.html">Accueil</a></li> | |
<li class="active"><a href="exo1.php">Exercice 1</a></li> | |
<li><a href="exo2.php">Exercice 2</a></li> | |
</ul> | |
</div> | |
</div> | |
</nav> | |
<div class="container"> | |
<div class="jumbotron"> | |
<h1 class="page-header"> | |
<?php | |
// Si y'a une erreur : | |
if ($loggin_error == 1){ | |
echo "Faut mettre un mot de passe ça marche mieux"; | |
} | |
elseif ($loggin_error == 2){ | |
echo "Tu n'existes pas !"; | |
} | |
elseif (isset($connected_user)){ | |
echo "Hi ".$connected_user['name']." !"; | |
} | |
else { | |
echo "Hi !"; | |
} | |
?> | |
</h1> | |
</div> | |
<div class="row"> | |
<div class="col-md-4"></div> | |
<div class="col-md-4"> | |
<h1 class="page-header">Connectez-vous !</h1> | |
<form method="POST" action="exo1.php" class="form" id="form1"> | |
<div class="form-group"> | |
<label for="login">Login</label> | |
<input type="text" class="form-control" name="login"> | |
</div> | |
<div class="form-group"> | |
<label form="password">Password</label> | |
<input type="password" class="form-control" name="password"> | |
</div> | |
<div class="form-group clearfix"> | |
<button type="submit" class="btn btn-success pull-right">Login</button> | |
</div> | |
</form> | |
</div> | |
<div class="col-md-4"></div> | |
</div> | |
</div> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
</body> | |
</html> | |
<?php mysqli_close($connect); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment