travail en colab avec alexis et nicolas sur un partage

This commit is contained in:
Rafael GHOUAR-TOUSSAINT 2024-06-13 18:06:02 +02:00
parent aad22c9bc7
commit f154a81961

View File

@ -1,32 +1,75 @@
<?php
// Informations de connexion à la base de données
$db = mysqli_connect("dwarves.iut-fbleau.fr","ghouar-t","Bases2023","ghouar-t");
if(!$db){
die("Connexion BD impossible.");
}else{
echo "Connexion BD reussie ! <br>";
require_once 'common.php';
session_start();
if (!empty($_REQUEST['login']) && !empty($_REQUEST['password'])) {
$db = initDatabase();
$login = $_POST['login'];
$password = $_POST['password'];
$role = $_POST['role'];
$password_hash = password_hash($password, PASSWORD_DEFAULT);
$verif=mysqli_query($db,"SELECT * FROM user WHERE login = '$login' ");
$result="INSERT INTO user VALUES('$login','$password_hash','$role')";
if (mysqli_num_rows($verif) == 0) {
if (mysqli_query($db,$result)) {
header('Location: connexion.php');
exit();
}
else {
die("erreur");
}
}
else {
echo 'login déjà utilisé';
header('Location: inscription.php');
echo 'login déjà utilisé';
}
}
// Récupération des données du formulaire
$login = $_POST['login'];
$password = $_POST['password'];
$role = $_POST['role'];
/*$stmt = mysqli_prepare($db,
"INSERT INTO user (login, mdp)
VALUES (?,?)");*/
?>
$password_hash = password_hash($password, PASSWORD_DEFAULT);
$query_insert = "INSERT INTO user (login, mdp, Role) VALUES ('$login', '$password_hash','$role')";
<html lang="fr">
<head>
<meta charset="utf-8">
<link rel="icon" href="../img/jo2024.jpg" >
<link rel="stylesheet" href="../css/style.css">
<title>Inscription - Jeux Olympiques</title>
</head>
<body>
if (mysqli_query($db, $query_insert)) {
echo "Inscription réussie !";
} else {
echo "Erreur lors de l'inscription : " . mysqli_error($db);
}
mysqli_close($db);
<div id="content_cours">
?>
<header>
<nav>
<a href="../index.php" class="categorie">Page d'accueil</a>
</nav>
</header>
<h2>Inscription</h2> <br>
<form action="" method="post">
<label for="login">Login :</label><br>
<input type="text" id="login" name="login" value="<?php if (isset($_REQUEST['login'])) { echo $_REQUEST['login']; } ?>"><br>
<label for="password">Mot de passe :</label><br>
<input type="password" id="password" name="password" required placeholder="••••••••" value="<?php if (isset($_REQUEST['login'])) { echo $_REQUEST['login']; } ?>"><br>
<label for="role">Role:</label>
<select id="role" name="role" required>
<option value="spectator">Spectator</option>
<option value="athlete">Athlete</option>
<option value="organizer">Organizer</option>
</select><br><br>
<input type="submit" value="Se connecter">
</form>
</body>
</html>