Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax Error - Confused 1

Status
Not open for further replies.

Krus1972

Programmer
Mar 18, 2004
145
0
0
US
I am using the following code to create tables within a MySQL database:

Code:
// Connect to the database
mysql_connect("$mysql_host","$mysql_username","$mysql_passwd") or die (mysql_error()); 
mysql_select_db("$mysql_dbase") or die (mysql_error());

// Create the tables
mysql_query("CREATE TABLE $redir_table ( host varchar(100) NOT NULL default '', name varchar(25) NOT NULL default '', vname varchar(25) NOT NULL default '', passwd varchar(50) NOT NULL default '', email varchar(100) NOT NULL default '', url varchar(100) NOT NULL default '', title varchar(100) NOT NULL default '', descr text NOT NULL, keyw text NOT NULL, counter int(11) default NULL, robots varchar(50) NOT NULL default '', news char(3) NOT NULL default '', revisit text NOT NULL, time varchar(15) NOT NULL default '', ip varchar(20) NOT NULL default '', cat varchar(50) NOT NULL default '', lasttime varchar(15) NOT NULL default '', stats char(3) NOT NULL default '', mail char(3) NOT NULL default '', adtype varchar(15) NOT NULL default '', acticode varchar(15) NOT NULL default '', active char(3) NOT NULL default '', PRIMARY KEY (host), UNIQUE KEY host (host) )") or die (mysql_error()); 
mysql_query("CREATE TABLE $options_table ( home varchar(50) NOT NULL default '', sitetitle varchar(150) NOT NULL default '', adminemail varchar(50) NOT NULL default '', username varchar(50) NOT NULL default '', password varchar(50) NOT NULL default '', domainip varchar(15) NOT NULL default '', maindomain varchar(50) NOT NULL default '', mailtoadmin char(3) NOT NULL default '', language varchar(20) NOT NULL default '', multiple char(3) NOT NULL default '', minlength char(2) NOT NULL default '', maxlength char(2) NOT NULL default '', reserved text NOT NULL, forbidden text NOT NULL, autoappr char(3) NOT NULL default '', theme varchar(50) NOT NULL default '', release varchar(10) NOT NULL default '' )") or die (mysql_error());
mysql_query("CREATE TABLE $domain_table ( domain varchar(50) NOT NULL default '' )") or die (mysql_error());
mysql_query("CREATE TABLE $category_table ( category varchar(50) NOT NULL default '', advtype varchar(20) NOT NULL default '', adurl varchar(150) NOT NULL default '', height varchar(4) NOT NULL default '', width varchar(4) NOT NULL default '' )") or die (mysql_error());
mysql_query("CREATE TABLE $visitor_table ( host varchar(100) NOT NULL default '', date varchar(15) NOT NULL default '', ip varchar(20) NOT NULL default '', agent varchar(250) NOT NULL default '', ref varchar(250) NOT NULL default '', timestamp varchar(15) NOT NULL default '' )") or die (mysql_error());

The database parameters and variables in the top three lines are defined much earlier in my code and are not printed in the above code.

The script connects to the database with no problems. I am receiving the following error when the code creates the database tables:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'release varchar(10) NOT NULL default '' )' at line 1

I am using MySQL version 5.5

I would appreciate any help in fixing ALL of the above syntax for this MySQL version.

Thanks so much




 
Print the MySQL query to the browser so you can see the actual concatenated query to locate the error is a debugging tip.

HOWEVER "release" is a reserved word in MySQL so should NOT be used as a column name OR should be enclosed in backticks (different to apostrophes).

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Additionally to Chris' advice, consider running troublesome queries in MySQL directly. If you utilize a MySQL GUI frontend tool like MySQL Workbench, SQLyog, HeidiSQL, or many others...the syntax highlighting of your queries may better illustrate where you've jumped off the track...if your PHP editor is not already illustrating the issue with syntax.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top