Show sourcecode
The following files exists in this folder. Click to view.
public_html/exercises/databas/ovn_db1/
createtable.php
deletepost.php
index.html
insertpost.php
selectposts.php
showtable.php
updatepost.php
createtable.php
40 lines ASCII Windows (CRLF)
<!-- createtable.php -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Create</title>
</head>
<body>
<form action="index.html" method="get"><button type="submit">Tillbaka till meny</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 kompisar (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30),
lastname VARCHAR(30),
mobilenumber VARCHAR(20),
email VARCHAR(50)
)";
// use exec() because no results are returned
$dbconn->exec($sql);
echo "Table created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
//Rensa kopplingen till databasen
$dbconn = null;
?>
</body>
</html>