Jump to content

MySQL Syntax Error


Recommended Posts

I want to make a php script that will setup my tables for me, but I'm getting errors when I try to do this. The odd thing is that it says that the syntax error occurs on line 8, but the script doesn't fail until around line 170.

 

Here's my code: (Config.php just contains my db information, which I have double checked)

 

<?php 

require_once("config.php");
//require_once("functions.php");

mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error()); 
mysql_select_db($dbname) or die(mysql_error()); 
echo "<br />Connected to database";

mysql_query("CREATE TABLE page_types(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
type_name VARCHAR(30))") 
or die(mysql_error());
echo "<br />Creating Table page_types";

mysql_query("INSERT INTO page_types (type_name) VALUES 
('sexperts'),
('generic'),
('itempopup'),
('photogallery'),
('totaledit'),
('library'),
('events')") 
or die(mysql_error()); 
echo "<br />Filling Table";

mysql_query("CREATE TABLE product_types(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
type_name VARCHAR(30))") 
or die(mysql_error());
echo "<br />Creating Table product_types";

mysql_query("INSERT INTO product_types (type_name) VALUES 
('condom'),
('lube'),
('misc')")
or die(mysql_error());  
echo "<br />Filling Table";

mysql_query("CREATE TABLE lib_item_types(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
type_name VARCHAR(30))") 
or die(mysql_error());
echo "<br />Creating Table lib_item_types";

mysql_query("INSERT INTO lib_item_types (type_name) VALUES 
('dvd'),
('vhs'),
('book'),
('pamphlet'),
('other')")
or die(mysql_error());  
echo "<br />Filling Table";

mysql_query("CREATE TABLE content_page(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
doc_title VARCHAR(50), 
page_title VARCHAR(75), 
leftcolumn TEXT, 
rt_col_title TEXT, 
rt_col1_text TEXT, 
horizontal_rule1 TEXT, 
rt_col2_text TEXT, 
horizontal_rule2 TEXT, 
rt_col_3_text TEXT)") 
or die(mysql_error());
echo "<br />Creating Table content_page";

mysql_query("CREATE TABLE lib_items(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
item_type TINYINT(3), 
item_name VARCHAR(255), 
checked_in BOOL, 
item_year YEAR(4), 
item_desc TEXT)") 
or die(mysql_error());
echo "<br />Creating Table lib_items";

mysql_query("CREATE TABLE users(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
user_name VARCHAR(50), 
user_pw VARCHAR(255))") 
or die(mysql_error());
echo "<br />Creating Table users";

mysql_query("CREATE TABLE events(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
start_date DATE,  
end_date DATE, 
start_time TIME,
end_time TIME, 
event_location VARCHAR(255), 
event_desc TEXT)") 
or die(mysql_error());
echo "<br />Creating Table events";

mysql_query("CREATE TABLE products(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
item_type TINYINT(3), 
item_name VARCHAR(255), 
extend_info TEXT, 
item_desc TEXT, 
item_picture VARCHAR(255)") 
or die(mysql_error());
echo "<br />Creating Table products";

mysql_query("CREATE TABLE center_info(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
phone_num VARCHAR(20), 
hotline_num VARCHAR(20), 
mon_hours VARCHAR(40), 
tues_hours VARCHAR(40), 
wed_hours VARCHAR(40), 
thurs_hours VARCHAR(40), 
fri_hours VARCHAR(40), 
sat_hours VARCHAR(40), 
sun_hours VARCHAR(40), 
location TEXT, 
email VARCHAR(255))") 
or die(mysql_error());
echo "<br />Creating Table center_info";



echo "<br />Tables Created!";
?>

 

Here is the output after running:

Connected to database

Creating Table page_types

Filling Table

Creating Table product_types

Filling Table

Creating Table lib_item_types

Filling Table

Creating Table content_page

Creating Table lib_items

Creating Table users

Creating Table eventsYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 8

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...