Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/ovning9/1/
laggatill.php
skapatabell.php
skriverut.php
tabort.php
uppdatera.php
skapatabell.php
47 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 kompisar (
idnummer INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
mobil INT,
email VARCHAR(30) NOT NULL
)";
// use exec() because no results are returned
$dbconn->exec($sql);
echo "Table created successfully";
$sql = "INSERT INTO kompisar (firstname, lastname, mobil, email)
VALUES (?, ?, ?, ?')";
$stmt = $dbconn->prepare($sql);
$data= array('Daniel', 'EO', '727713092', 'danieleh@varmdogymnasium.se');
$dbconn->exec($sql);
$data= array('Anton', 'AL', '727783823', 'antonad@varmdogymnasium.se');
$dbconn->exec($sql);
$data= array('Peter', 'GR', '736801554', 'petergr@varmdogymnasium.se');
$dbconn->exec($sql);
echo "Default posts added successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
//Rensa kopplingen till databasen
$dbconn = null;
?>
<a href="../ovn_sql1.php">Tillbaks till meny</a>
</body>
</html>