Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbserverprogrammering/projekt/snake_oil_seller/php/

about_us.php
add_to_cart.php
admin.php
buy_cart.php
config.php
contact.php
create_products.php
create_tables.php
createtable.php
dbconnection.php
delete_post.php
delete_tables.php
deletepost.php
deletetable.php
entry.php
header.php
insert_posts.php
insertposts.php
leaderboard.php
log_in.php
log_out.php
main.php
my_account.php
question_maker.php
quiz_form.php
quiz_list.php
quiz_maker.php
result.php
select_posts.php
selectposts.php
shop.php
shop_item.php
shopping_cart.php
sign_in.php
title_card.php
update_posts.php
updateposts.php
user_verified.php
verify_page.php

create_tables.php

127 lines UTF-8 Windows (CRLF)
<!-- createtable.php -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Create table</title>
</head>
<body>
<?php
include ('dbconnection.php');

// Skapar tabell för användare
try { 

    
// Skapar tabell för konto
    
$sql "CREATE TABLE IF NOT EXISTS users (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
    username VARCHAR(30) NOT NULL,
    email VARCHAR(100),
    password VARCHAR(255) NOT NULL,
    usertype ENUM('user', 'admin') NOT NULL DEFAULT 'user',
    is_verified ENUM('yes', 'no') NOT NULL DEFAULT 'no',
    reg_date DATETIME
    )"
;

    
// use exec() because no results are returned
    
$dbconn->exec($sql);
    echo 
"Table users created successfully";
}
catch(
PDOException $e)
    {
    echo 
$sql "<br>" $e->getMessage();
}

echo 
"<br><br>";

try {
    
// Skapar tabell för produkt-klasser
    
$sql "CREATE TABLE IF NOT EXISTS product_classes (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
    name VARCHAR(30) NOT NULL,
    info VARCHAR(255) NOT NULL,
    discount FLOAT(6) NOT NULL DEFAULT 1,
    reg_date INT(20)
    )"
;

    
// use exec() because no results are returned
    
$dbconn->exec($sql);
    echo 
"Table product_classes created successfully";
}
catch(
PDOException $e)
    {
    echo 
$sql "<br>" $e->getMessage();
}

echo 
"<br><br>";

try {
    
// Skapar tabell för produkter
    
$sql "CREATE TABLE IF NOT EXISTS product_items (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
    name VARCHAR(30) NOT NULL,
    price DECIMAL(9,2),
    info VARCHAR(255) NOT NULL,
    img VARCHAR (255) NOT NULL,
    amount INT(6),
    type_id INT(6),
    reg_date INT(20)
    )"
;

    
// use exec() because no results are returned
    
$dbconn->exec($sql);
    echo 
"Table product_items created successfully";
}
catch(
PDOException $e)
    {
    echo 
$sql "<br>" $e->getMessage();
}

echo 
"<br><br>";

try {
    
// Skapar tabell för alla köp
    
$sql "CREATE TABLE IF NOT EXISTS orders (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
    user_id INT UNSIGNED,
    date INT(20),
    FOREIGN KEY (user_id) REFERENCES users(id)
    )"
;

    
// use exec() because no results are returned
    
$dbconn->exec($sql);
    echo 
"Table orders created successfully";
}
catch(
PDOException $e)
    {
    echo 
$sql "<br>" $e->getMessage();
}

echo 
"<br><br>";

try {
    
// Skapar tabell för alla köpta produkter
    
$sql "CREATE TABLE IF NOT EXISTS order_items (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    order_id INT UNSIGNED,
    product_id INT UNSIGNED,
    amount INT,
    FOREIGN KEY (order_id) REFERENCES orders(id),
    FOREIGN KEY (product_id) REFERENCES product_items(id)
    )"
;

    
// use exec() because no results are returned
    
$dbconn->exec($sql);
    echo 
"Table order_items created successfully";
}
catch(
PDOException $e)
    {
    echo 
$sql "<br>" $e->getMessage();
}

//Rensa kopplingen till databasen
$dbconn null;

?>
</body>
</html>