I'm teaching mysql and php , i 'm creating simple database for bookstore whatever i created file booksite.php(script)
<?php //connect to MySQL; note we've used our own parameters- you should use //your own for hostname, user, and password $connect = mysql_connect("localhost", "root", "root") or die ("Hey loser, check your server connection."); //create the main database if it doesn't already exist $create = mysql_query("CREATE DATABASE IF NOT EXISTS booksite") or die(mysql_error()); //make sure our recently created database is the active one mysql_select_db("booksite"); //create "title" table $title = " DROP TABLE IF EXISTS title CREATE TABLE title( title_id int(20) NOT NULL auto_increment, title_name varchar(255) NOT NULL, title_type tinyint(2) NOT NULL default 0, title_year int(4) NOT NULL default 0, title_serial int(11) NOT NULL default 0, title_level int(11) NOT NULL default 0, PRIMARY KEY (title_id), KEY book_type (title_type,title_year) )"; $results = mysql_query($title) or die (mysql_error()); //create "author" table $author = "CREATE TABLE author ( author_id int(11) NOT NULL auto_increment, author_label varchar(100) NOT NULL, PRIMARY KEY (author_id) )"; $results = mysql_query($author) or die(mysql_error()); //create "instructor" table $insructor= "CREATE TABLE instructor ( instructor_id int(11) NOT NULL auto_increment, instructor_fullname varchar(255) NOT NULL, instructor_number tinyint(1) NOT NULL default 0, PRIMARY KEY (instructor_id) )"; $results = mysql_query($instructor) or die(mysql_error()); echo "booksite Database successfully created!";
I fixed the formatting
I have fixed the formatting in this post, anyway the line breaks wasn't visible so i tried to fix the code with my common sense (i dunno php), Anyway if i have done something wrong regarding the line breaks please someone tells me what to do.
Thanks
Ahmed D. El-Mekkawy
this : $title = " DROP
this :
$title = " DROP TABLE IF EXISTS title CREATE TABLE title( title_id int(20) NOT NULL auto_increment, title_name varchar(255) NOT NULL, title_type tinyint(2) NOT NULL default 0, title_year int(4) NOT NULL default 0, title_serial int(11) NOT NULL default 0, title_level int(11) NOT NULL default 0, PRIMARY KEY (title_id), KEY book_type (title_type,title_year) )";
should be:
$title = "DROP TABLE IF EXISTS title ; CREATE TABLE title( title_id int(20) NOT NULL auto_increment, title_name varchar(255) NOT NULL, title_type tinyint(2) NOT NULL default 0, title_year int(4) NOT NULL default 0, title_serial int(11) NOT NULL default 0, title_level int(11) NOT NULL default 0, PRIMARY KEY (title_id), KEY book_type (title_type,title_year) )";