<?php
mysql_connect ("localhost", "root","panda") or die (mysql_error());
$create=mysql_query ("CREATE DATABASE IF NOT EXISTS sucko_shop") or die (mysql_error());
mysql_select_db("sucko_shop");
$table= "CREATE TABLE product_category (
category_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
category_name VARCHAR (50) NOT NULL DEFAULT '',
category_description VARCHAR (200) NOT NULL DEFAULT '',
category_image VARCHAR (200) NOT NULL DEFAULT '',
PRIMARY KEY (category_id),
)";
$query=mysql_query($table);
$table2="CREATE TABLE tableof_products (
product_id INTEGER UNSIGNED NOT NULL AUTO INCREMENT,
product_name VARCHAR (100) NOT NULL DEFAULT '',
product_description TEXT NOT NULL DEFAULT '',
product_price DECIMAL (7,2) NOT NULL DEFAULT 0.00,
product_quantity SMALLINT UNSIGNED NOT NULL DEFAULT 0,
producurrency_image VARCHAR (200),
primary key (product_id)
)";
$query2=mysql_query($table2);
$table3="CREATE TABLE shopping_cart (
cart_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
product_id INTEGER UNSIGNED NOT NULL,
cart_quantity INTEGER UNSIGNED NOT NULL DEFAULT 1,
cart_session_id CHAR (30) NOT NULL DEFAULT '',
cart_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (cart_id)
)";
$query3=mysql_query($table3);
$table4="CREATE TABLE customer_order (
order_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
order_date DATETIME NOT NULL DEFAULT '0000-00-00 '00:00:00',
order_status ('Awaiting payment', 'Sent', 'Cancelled'),
order_shipping_first_name VARCHAR (20) NOT NULL DEFAULT '',
order_shipping_last_name VARCHAR (30) NOT NULL DEFAULT '',
order_shipping_address1 VARCHAR (100) NOT NULL DEFAULT '',
order_shipping_address2 VARCHAR (100) NOT NULL DEFAULT '',
order_shipping_city VARCHAR (100) NOT NULL DEFAULT '',
order_shipping_post_code VARCHAR (15) NOT NULL DEFAULT '',
order_shipping_cost DECIMAL (5,2) DEFAULT 0.00 DEFAULT '',
order_payment_first_name VARCHAR (50) NOT NULL,
order_payment_last_name VARCHAR (50) NOT NULL DEFAULT '',
order_payment_address1 VARCHAR (100) NOT NULL DEFAULT '',
order_payment_address2 VARCHAR (100) NOT NULL DEFAULT '',
order_payment_city VARCHAR (100) NOT NULL DEFAULT '',
order_payment_postal_code VARCHAR (10) NOT NULL DEFAULT '',
PRIMARY KEY (order_id)
)";
$query4=mysql_query($table4);
$table5="CREATE TABLE tableorder_item (
order_id INTEGER UNSIGNED NOT NULL,
product_id INTEGER UNSIGNED NOT NULL,
order_quantity INTEGER UNSIGNED NOT NULL,
PRIMARY KEY (order_id, product_id)
)";
$query5=mysql_query($table5);
$table6="CREATE TABLE table_user (
user_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
user_name VARCHAR(20) NOT NULL DEFAULT '',
user_password VARCHAR(32) NOT NULL DEFAULT '',
user_registration_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
user_last_login DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (user_id),
UNIQUE KEY user_name (user_name)
)";
$query6=mysql_query($table6);
$insert="INSERT INTO table_user VALUES(1, 'admin', PASSWORD('admin'), NOW(), NOW())";
$results=mysql_query($insert) or die (mysql_error());
$table7="CREATE TABLE table_shop_config (
shopconfig_name VARCHAR(50) NOT NULL DEFAULT '',
shopconfig_address VARCHAR(100) NOT NULL DEFAULT '',
shopconfig_phone VARCHAR(30) NOT NULL DEFAULT '',
shopconfig_email VARCHAR(30) NOT NULL DEFAULT '',
shopconfig_shipping_cost DECIMAL(5,2) NOT NULL DEFAULT 0.00,
shopconfig_currency INTEGER unsigned NOT NULL DEFAULT 1
)";
$query7=mysql_query($table7);
$insert2="INSERT INTO table_shop_config VALUES ('', '', '', '', 0.00, 1)";
$results2=mysql_query($insert2) or die (mysql_error());
$table8="CREATE TABLE table_currency (
currencurrency_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
currencurrency_code CHAR(3) NOT NULL,
currencurrency_symbol VARCHAR(8) NOT NULL,
PRIMARY KEY (currency_id)
)";
$query8=mysql_query($table8);
$insert3="INSERT INTO table_currency (currency_id, currency_code, currency_symbol) VALUES (1, 'EUR', '€')";
$results3=mysql_query($insert3) or die (mysql_error());
$insert4="INSERT INTO table_currency (currencurrency_id, currency_code, currency_symbol) VALUES (2, 'GBP', '£')";
$results4=mysql_query($insert4) or die (mysql_error());
$insert5="INSERT INTO table_currency (currency_id, currency_code, currency_symbol) VALUES (3, 'JPY', '¥')";
$results5=mysql_error($insert5) or die (mysql_error());
$insert6="INSERT INTO table_currency (currency_id, currency_code, currency_symbol) VALUES (4, 'USD', '$')";
$results6=mysql_error($insert6) or die (mysql_error());
?>
Hi guys,
I have amended my code to include queries to actually create the tables. I have a GUI client for SQL, Mysql adminstrator, and when I checked the results of my code being executed, it seems that ALL the tables have been created save for ONE.
Whenever I execute my code I get the following message:
Table 'sucko_shop.table_currency' doesn't exist.
I checked the MySQL Adminstrator and lo and behold, there is a number of tables, with that table omitted.
I am not quite sure what I have done wrong (yet again, some silly error I imagine)...really appreciate your help again guys :o