Stephen Lunzaga
Stephen Lunzaga

Reputation: 1

SQL error while executing the query

4 errors were found during analysis.

Ending quote ' was expected. (near "" at position 510)

A comma or a closing bracket was expected. (near "', `email` varchar(100) NOT NULL, `active` int(1) NOT NULL default ‘0'" at position 181)

Unexpected beginning of statement. (near "20" at position 268)

Unrecognized statement type. (near "NOT NULL" at position 272)

SQL query:

CREATE TABLE IF NOT EXISTS `users`
(
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(32) NOT NULL,
  `password` varchar(32) NOT NULL,
  `online` int(20) NOT NULL default ‘0',
  `email` varchar(100) NOT NULL,
  `active` int(1) NOT NULL default ‘0',
  `rtime` int(20) NOT NULL default ‘0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

INSERT INTO `users` (`id`, `username`, `password`, `online`, `email`, `active`, `rtime`) 
VALUES (1, ‘testing’, ‘testing’, 0, ‘[email protected]’, 0, 0); 

Upvotes: 0

Views: 10206

Answers (6)

Arulkumar
Arulkumar

Reputation: 13237

  • No need of any quote around the default value zero

  • You need to replace the single quote ' instead of the , quotes in the INSERT query.

The working code will be

CREATE TABLE IF NOT EXISTS `users` (
  `id`       int(11)      NOT NULL auto_increment,
  `username` varchar(32)  NOT NULL, 
  `password` varchar(32)  NOT NULL, 
  `online`   int(20)      NOT NULL default 0, -- here
  `email`    varchar(100) NOT NULL, 
  `active`   int(1)       NOT NULL default 0, -- here
  `rtime`    int(20)      NOT NULL default 0, -- here
  PRIMARY KEY (`id`) 
) ENGINE = MyISAM DEFAULT CHARSET=utf8; 

INSERT INTO `users` (`id`, `username`, `password`, `online`, `email`, `active`, `rtime`) 
VALUES (1, 'testing', 'testing', 0, '[email protected]', 0, 0); -- here

SQL Fiddle DEMO: http://sqlfiddle.com/#!9/286728/1

Upvotes: 0

Saibal Roy
Saibal Roy

Reputation: 431

Sql Executed

Please correctly select the Database first:

Copy the below given SQL in the SQL editor and execute it. Hope this solves your problem. Thanks.

CREATE TABLE IF NOT EXISTS `users`
(
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(32) NOT NULL,
  `password` varchar(32) NOT NULL,
  `online` int(20) NOT NULL default '0',
  `email` varchar(100) NOT NULL,
  `active` int(1) NOT NULL default '0',
  `rtime` int(20) NOT NULL default '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

INSERT INTO `users` (`id`, `username`, `password`, `online`, `email`, `active`, `rtime`) 
VALUES (1, 'testing', 'testing', 0, '[email protected]', 0, 0);

Upvotes: 0

juergen d
juergen d

Reputation: 204756

You use a different kind of quote character for instance

`online` int(20) NOT NULL default ‘0', 
         here --------------------^

Replace it with a normal one every time you use it

CREATE TABLE IF NOT EXISTS `users`
(
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(32) NOT NULL,
  `password` varchar(32) NOT NULL,
  `online` int(20) NOT NULL default '0',
  `email` varchar(100) NOT NULL,
  `active` int(1) NOT NULL default '0',
  `rtime` int(20) NOT NULL default '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

But since the type of those columns is int you don't need quotes around the default values at all.

Upvotes: 2

train_fox
train_fox

Reputation: 1537

Try this:

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(32) NOT NULL,
  `password` varchar(32) NOT NULL,
  `online` int(20) NOT NULL DEFAULT '0',
  `email` varchar(100) NOT NULL,
  `active` int(1) NOT NULL DEFAULT '0',
  `rtime` int(20) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

And:

INSERT INTO users (id, username, password, online, email, active, rtime) VALUES (1, 'testing', 'testing', 0, '[email protected]', 0, 0);

Upvotes: 0

DirtyBit
DirtyBit

Reputation: 16772

You are using different types of quotes together ' with

Replace this:

CREATE TABLE IF NOT EXISTS `users`
(
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(32) NOT NULL,
  `password` varchar(32) NOT NULL,
  `online` int(20) NOT NULL default ‘0',
  `email` varchar(100) NOT NULL,
  `active` int(1) NOT NULL default ‘0',
  `rtime` int(20) NOT NULL default ‘0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

INSERT INTO `users` (`id`, `username`, `password`, `online`, `email`, `active`, `rtime`) 
VALUES (1, ‘testing’, ‘testing’, 0, ‘[email protected]’, 0, 0);

With this:

CREATE TABLE IF NOT EXISTS `users`
(
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(32) NOT NULL,
  `password` varchar(32) NOT NULL,
  `online` int(20) NOT NULL default '0',
  `email` varchar(100) NOT NULL,
  `active` int(1) NOT NULL default '0',
  `rtime` int(20) NOT NULL default '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;



INSERT INTO `users` (`id`, `username`, `password`, `online`, `email`, `active`, `rtime`) 
VALUES (1, 'testing', 'testing', 0, '[email protected]', 0, 0); 

Upvotes: 0

Tanmay Majumder
Tanmay Majumder

Reputation: 372

Just remove '' quotes from 0 for all Int datatype.

CREATE TABLE IF NOT EXISTS users ( id int(11) NOT NULL auto_increment, username varchar(32) NOT NULL, password varchar(32) NOT NULL, online int(20) NOT NULL default 0, email varchar(100) NOT NULL, active int(1) NOT NULL default 0, rtime int(20) NOT NULL default 0, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Upvotes: 1

Related Questions