Show sourcecode
The following files exists in this folder. Click to view.
public_html/exercises/databas/ovn_db2/admin/
adduser.php
createtable.php
deleteuser.php
edituser.php
createtable.php
42 lines ASCII Windows (CRLF)
<!-- createtable.php -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Create</title>
</head>
<body>
<form action="index.php" method="get"><button type="submit">Back to welcome page</button></form>
<?php
include('../../dbconnection.php');
if (!$dbconn) {
die("Connection failed: Can't connect to database.");
}
try {
// sql to create table
$sql = "CREATE TABLE IF NOT EXISTS users (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(10) NOT NULL UNIQUE,
password VARCHAR(30) NOT NULL,
is_admin BOOLEAN,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";
// use exec() because no results are returned
$dbconn->exec($sql);
echo "Users table created successfully";
} catch (PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
//Rensa kopplingen till databasen
$dbconn = null;
?>
</body>
</html>