Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/ovning9/2/
admin.php
deletetable.php
laggtill.php
skapatabell.php
skriverut.php
uppdatera.php
welcome.php
skapatabell.php
51 lines ASCII Windows (CRLF)
<!-- createtable.php -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Create</title>
</head>
<body>
<?php
include ('../dbconnection.php');
try {
// sql to create table
$sql = "CREATE TABLE anvandaretabell (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
anvandare VARCHAR(30) NOT NULL,
passw VARCHAR(30) NOT NULL,
typ VARCHAR(9) NOT NULL,
reg_date DATETIME
)";
// use exec() because no results are returned
$dbconn->exec($sql);
echo "Table created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
try{
$sql = "INSERT INTO anvandaretabell (firstname, lastname, anvandare, passw, typ, reg_date)
VALUES ('Daniel', 'EO', 'adminn', 'adminn', 'adminn', now())";
$dbconn->exec($sql);
echo "Admin created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
//Rensa kopplingen till databasen
$dbconn = null;
?>
<a href="../ovn_sql2.php">Tillbaks till meny</a>
</body>
</html>