Show sourcecode
The following files exists in this folder. Click to view.
ramverket/exercises/mysql-intro/
ovn_sqlintr1.php
ovn_sqlintr2.php
ovn_sqlintr2.php
80 lines UTF-8 Windows (CRLF)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
<?php
// Title: MySQL Intro 2
error_reporting(-1); // Report all type of errors
ini_set('display_errors', 1); // Display all errors
ini_set('output_buffering', 0); // Do not buffer outputs, write directly
?>
<?php include("../../incl/connect_db.php"); ?>
<?php include("../../incl/db_handler.php"); ?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MySQL Intro 2</title>
</head>
<body>
<?php
$table = "users";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['delete_all'])) {
deleteAllTableRows($conn);
}
if (isset($_POST['insert_row'])) {
insertTableRow($conn, $table, $_POST['first_name'], $_POST['last_name'], $_POST['mobile'], $_POST['email']);
}
if (isset($_POST['delete_row'])) {
deleteTableRow($conn, $table, $_POST['id']);
}
if (isset($_POST['update_row'])) {
updateTableRow($conn, $table, $_POST['id'], $_POST['first_name'], $_POST['last_name'], $_POST['mobile'], $_POST['email']);
}
if (isset($_POST['to_register'])) {
}
if (isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if (login($conn, $table, $username, $password)) {
setcookie("username", $username, time() + (86400 * 30), "/");
} else {
echo "Fel användarnamn eller lösenord";
}
}
header("Location: ovn_sqlintr2.php");
exit();
}
if (!tableExists($conn, $table)) {
createTable($conn, $table);
}
?>
<?php if (isset($_COOKIE['username'])): ?>
<h1>Hej <?php echo $_COOKIE['username']; ?>!</h1>
<?php else: ?>
<form action="" method="POST">
<input type="text" name="username" placeholder="Användarnamn">
<input type="password" name="password" placeholder="Lösenord">
<input type="submit" name="login" value="Logga in">
</form>
<form action="" method="POST">
<input type="submit" name="to_register" value="Skapa konto">
</form>
<?php endif; ?>
<style>
th {
text-align: start;
}
</style>
</body>
</html>