Browse Source

Bestanden uploaden naar ''

if-else
LanderNeufcourt 3 years ago
parent
commit
71cd5f0075
3 changed files with 156 additions and 43 deletions
  1. BIN
      db.sqlite
  2. 65
    43
      index.php
  3. 91
    0
      login.php

BIN
db.sqlite View File


+ 65
- 43
index.php View File

@@ -1,44 +1,66 @@
<html>
<!-- Hier start het php-script te lopen -->

<body>


<?php
// Naar php-modus
$pos = rand(0, 20);
$ammo = 3;
$win = false;
$shot = $pos ?>

<!-- Terug in HTML modus -->
<h2>Zeeslag</h2>
<form action="/zeeslag/index.php" method="POST">
<label for="shot">Shot: </label><br>
<input type="text" id="shot" name="shot" required>
<input type="submit" value="submit">
</form>

<?php
// In PHP
if ($shot == $pos){
$ammo--;
$win = true;
echo ['you won']
}
if ($shot != $pos){
$ammo--;
$win = false
echo ['try again']
}
if ($ammo = 0) {
echo ['you lose']
}
?>
<!-- HTML -->
</body>

<!-- Hier wordt de pagina met gerenderd formulier naar de browser gestuurd -->

<?php
session_start();
if (isset($_POST['register'])){
$db = new SQLite3 ("db.sqlite");
$username = $_POST['username'];
$password = $_POST['password_1'];
$sql = "INSERT INTO users (username, password) VALUES ($username, $password)";
//$stmt->prepare($sql);
$db->exec($sql);
echo "You are registered";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<header>
<h2>Register</h2>
</header>
<form method="POST" action="index.php">
<div class="input-group">
<label>Username</label>
<input type="text" name="username">
</div>
<div class="input-group">
<label>Email</label>
<input type="text" name="email">
</div>
<div class="input-group">
<label>Password</label>
<input type="password" name="password_1">
</div>
<div class="input-group">
<label>Confirm Password</label>
<input type="password" name="password_2">
</div>
<div class="input-group">
<button type="submit" name="register" class="btn">Register</button>
</div>
<p>
Already signed up? <a href="login.php">Sign in</a>
</p>
</form>
</body>
</html>

+ 91
- 0
login.php View File

@@ -0,0 +1,91 @@
<?php
session_start();
if (isset($_POST['login'])){
//Registratie form
function checkLogin ($username, $password) {}
$db = new SQLite3 ("db.sqlite");
$username = $_POST['username'];
$password = $_POST['password_1'];
//Login Form
//$sql = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$stmt = $db->prepare("SELECT * FROM users WHERE login = :usrn AND password = :passw");
$stmt->bindValue(":usrn", $username, SQLITE3_TEXT);
$stmt->bindValue(":pass", $password, SQLITE3_TEXT);
$res = $stmt->execute();
if ($row = $res->fetchArray(SQLITE3_ASSOC)){
$id = $row['id'];
$res = $db->query("INSERT INTO game('user_id', 'won') VALUES ($id,true)");
} else {
echo "Gebruiker bestaat niet";
echo "<a href=\"index.php\">Sign up</a>";
}
//$stmt_insert = $db->prepare("INSERT INTO users('login', 'password') VALUES(:usrn, :pass)");
//$stmt_insert->bindValue(":usrn", $username, SQLITE3_TEXT);
//$stmt_insert->bindValue(":pass", $password, SQLITE3_TEXT);
//$res = $stmt_insert->execute();
//if ($res){
// echo "Gebruiker " . $username . " aangemaakt.";
//} else {
// $errorCode = $db->lastErrorCode();
// $errorMessage = $db->lastErrorMsg();
// echo "Database error wiht ocde " . $errorCode . " and message " . $errorMessage;
//}
//Wat bij duplicates?
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<header>
<h2>Login</h2>
</header>
<form method="POST" action="login.php">
<div class="input-group">
<label>Username</label>
<input type="text" name="username">
</div>
<div class="input-group">
<label>Password</label>
<input type="password" name="password_1">
</div>
<div class="input-group">
<button type="submit" name="login" class="btn">Login</button>
</div>
<p>
Not signed up yet? <a href="index.php">Sign up</a>
</p>
</form>
</body>
</html>

Loading…
Cancel
Save