1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
PHP_TP2/createUser.php
2020-09-12 14:31:17 +02:00

44 lines
1.5 KiB
PHP

<?php
require("header.php");
if ($_POST["username"] AND $_POST["word"] AND $_POST["nb"]) {
$username = htmlspecialchars($_POST["username"]);
$word = htmlspecialchars($_POST["word"]);
$nb = (int) $_POST["nb"];
$bdd = getPDO();
if ($bdd INSTANCEOF PDO)
try {
$req = $bdd->prepare("SELECT * FROM user WHERE username = ?");
$req->execute(array($username));
if ($req->fetch()) { ?>
<p><strong>Username already exist !</strong></p>
<?php } else {
$req->closeCursor();
$req = $bdd->prepare("INSERT INTO user VALUES (?, ?, ?)");
$req->execute(array($username, $word, $nb));
$_SESSION["p1905458"] = $username;
header("Location: helloworld4.php");
}
$req->closeCursor();
} catch (Exception $e) {
databaseError($e);
}
elseif ($bdd INSTANCEOF Exception)
databaseError($bdd);
}
?>
<form method="POST">
<label for="username">Username: </label>
<input id="username" name="username" required> <br />
<label for="word">Word: </label>
<input id="word" name="word" required> <br />
<label for="nb">Number: </label>
<input id="nb" type="number" name="nb" min="0" max="100" required> <br />
<input type="submit">
</form>
<?php require("footer.php") ?>