43 lines
1.5 KiB
PHP
43 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") ?>
|