dt_gry Posted September 19, 2008 Share Posted September 19, 2008 Hi guys, I am trying to automate database table creation using database.sql (executing in puTTY) and I am getting the following error ./database.sql: line 1: syntax error near unexpected token `(' ./database.sql: line 1: `CREATE TABLE 'users' (' Here is my code: CREATE TABLE 'users' ( 'id' int(11) NOT NULL auto_increment, 'username' varchar(30) NOT NULL default '', 'password' varchar(40) NOT NULL default '', 'email' varchar(140) NOT NULL default '', 'regdate' int(10) NOT NULL default '0', 'ip' varchar(15) NOT NULL default '', 'lastdate' int(10) NOT NULL default '0', PRIMARY KEY ('id') ); CREATE TABLE 'forgot' ( 'username' varchar(30) NOT NULL default '', 'password' varchar(40) NOT NULL default '', 'email' varchar(140) NOT NULL default '', 'regdate' int(10) NOT NULL default '0', 'ip' varchar(15) NOT NULL default '' ); Any ideas? Thanks dt_gry Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted September 19, 2008 Share Posted September 19, 2008 I dont think you need the single quotes around 'users' Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 Yes, I believe that when you're referring to table and column names, you use "double quotes" and when referring to data, you use 'single quotes.' Quote Link to comment Share on other sites More sharing options...
Stooney Posted September 19, 2008 Share Posted September 19, 2008 I don't believe you need any of the single quotes. You can however use backdrops (`) where needed. Quote Link to comment Share on other sites More sharing options...
dt_gry Posted September 19, 2008 Author Share Posted September 19, 2008 That didn't work. New CODE CREATE TABLE "users" ( `id` int(11) NOT NULL auto_increment, `username` varchar(30) NOT NULL default ``, `password` varchar(40) NOT NULL default ``, `email` varchar(140) NOT NULL default ``, `regdate` int(10) NOT NULL default `0`, `ip` varchar(15) NOT NULL default ``, `lastdate` int(10) NOT NULL default `0`, PRIMARY KEY (`id`) ); CREATE TABLE "forgot" ( `username` varchar(30) NOT NULL default ``, `password` varchar(40) NOT NULL default ``, `email` varchar(140) NOT NULL default ``, `regdate` int(10) NOT NULL default `0`, `ip` varchar(15) NOT NULL default `` ); Thanks dt_gry Quote Link to comment Share on other sites More sharing options...
Stooney Posted September 19, 2008 Share Posted September 19, 2008 You're problem lies with default. You need to specify a value like this: regdate int(10) NOT NULL default '0' So here's working code, without defaults CREATE TABLE users ( id int(11) NOT NULL AUTO_INCREMENT, username varchar(30) NOT NULL, password varchar(40) NOT NULL, email varchar(140) NOT NULL, regdate int(10) NOT NULL, ip varchar(15) NOT NULL, lastdate int(10) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE forgot ( username varchar(30) NOT NULL, password varchar(40) NOT NULL, email varchar(140) NOT NULL, regdate int(10) NOT NULL, ip varchar(15) NOT NULL ); Quote Link to comment Share on other sites More sharing options...
dt_gry Posted September 19, 2008 Author Share Posted September 19, 2008 Thanks chrisdburns, but I got the same error with the code you gave me. Any more ideas. Thanks dt_gry Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 What happens when you try this: CREATE TABLE "users" ( "id" int(11) NOT NULL AUTO_INCREMENT, "username" varchar(30) NOT NULL, "password" varchar(40) NOT NULL, "email" varchar(140) NOT NULL, "regdate" int(10) NOT NULL, "ip" varchar(15) NOT NULL, "lastdate" int(10) NOT NULL, PRIMARY KEY ("id") ); CREATE TABLE "forgot" ( "username" varchar(30) NOT NULL, "password" varchar(40) NOT NULL, "email" varchar(140) NOT NULL, "regdate" int(10) NOT NULL, "ip" varchar(15) NOT NULL ); Quote Link to comment Share on other sites More sharing options...
dt_gry Posted September 19, 2008 Author Share Posted September 19, 2008 ./database.sql: line 1: syntax error near unexpected token `(' ./database.sql: line 1: `CREATE TABLE "users" (' Quote Link to comment Share on other sites More sharing options...
Stooney Posted September 19, 2008 Share Posted September 19, 2008 The code I posted ran fine in phpMyAdmin. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 Yeah, it looks perfectly fine. Copy exactly what you're running and paste it here so we can see it. Maybe you're missing one little character that you're not seeing, but we will. Quote Link to comment Share on other sites More sharing options...
dt_gry Posted September 19, 2008 Author Share Posted September 19, 2008 I am going into putty and doing this I login I go to the directory where database.sql is located lastly I type ./database.sql I thought I might be executing it wrong but wasn't sure. Thanks Guys, dt_gry Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.