phpMyAdmin create table ERROR

A

Anonymous

Guest
Hi,
I created a database Temp and when I try to input this create table Data (which I got from a website tutorial) I get this message, What is wrong...the Data or my phpmyadmin or mySQL?
----------------------------------
Error

SQL query:

CREATE TABLE 'tutorials'(
'ID'tinyint( 11 ) NOT NULL AUTO_INCREMENT ,
'title'text NOT NULL ,
'avatar'text NOT NULL ,
'date'date NOT NULL default '0000-00-00',
'description'text NOT NULL ,
'user'text NOT NULL ,
'message'text NOT NULL ,
PRIMARY KEY ( 'ID' )
) TYPE = MYISAM AUTO_INCREMENT =1;

MySQL said: Documentation
#1064 - 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 ''tutorials' (
'ID' tinyint(11) NOT NULL auto_increment,
'title' text NOT NULL,' at line 1
---------------------------------------
 
I think you have used single quote (') instead of back tick (`).
Use back tick (`) in Table Name and Field Names.
 
Hi,
NO it still gives the error.
And its not the ` since it was corectly the '
What else could it be?
 
I manualy inserted the table...is this SQL phpmyadmin created the same as the first?
-----------------------------------
CREATE TABLE `tutorials` (
`ID` TINYINT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` TEXT NOT NULL ,
`avatar` TEXT NOT NULL ,
`date` DATE NOT NULL DEFAULT '0000-00-00',
`description` TEXT NOT NULL ,
`user` TEXT NOT NULL ,
`message` TEXT NOT NULL
) ENGINE = MYISAM ;
-----------------------------
 
Second one is working.

1.

CREATE TABLE 'tutorials'(
'ID'tinyint( 11 ) NOT NULL AUTO_INCREMENT ,
'title'text NOT NULL ,
'avatar'text NOT NULL ,
'date'date NOT NULL default '0000-00-00',
'description'text NOT NULL ,
'user'text NOT NULL ,
'message'text NOT NULL ,
PRIMARY KEY ( 'ID' )
) TYPE = MYISAM AUTO_INCREMENT =1;

and
2.

CREATE TABLE `tutorials` (
`ID` tinyint(11) NOT NULL auto_increment,
`title` text NOT NULL,
`avatar` text NOT NULL,
`date` date NOT NULL default '0000-00-00',
`description` text NOT NULL,
`user` text NOT NULL,
`message` text NOT NULL,
PRIMARY KEY (`ID`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

ARE NOT THE SAME.

For table names and field names USE BACK TICK (`) OR NOTHING.
 
Nice its working now...Thank you.
Is it a Database Software thing that MySQL does not use the normal ' ?
Or did the Website hosting the Tutiorial make an error?
Though it is a PHP/MySQL Tutorial System.
http://www.webdesign.org/web/web-programming/php/phpmysql-tutorial-system.8180.html
 
Yes, I think the example on that link is wrong. It doesnt work.

MySQL doesnt accept single quote (') for table names and field names.
For normal string we use single quote (').

e.g.

SELECT `fname`, `lname` FROM `tblusers` where userid = 'viral'
 
However, there's no need to use both single quotes (') or back tick (`).
Of course, i'm not talking about fields' values. Single quotes must be added when needed.
Example:
Code:
INSERT INTO table SET id=20, name='john';
 
gesf said:
However, there's no need to use both single quotes (') or back tick (`).
Of course, i'm not talking about fields' values. Single quotes must be added when needed.
Example:
Code:
INSERT INTO table SET id=20, name='john';


Exactly, gesf is right. I never use back tick (`) for table or field names. It is just for syntax knowledge.
 
gesf said:
However, there's no need to use both single quotes (') or back tick (`).
Of course, i'm not talking about fields' values. Single quotes must be added when needed.
Example:
Code:
INSERT INTO table SET id=20, name='john';

Yes, I usually use the double quotes at the beginning and at the end. In between there is nothing else as

$schedule = "CREATE TABLE pertile (
exam_year year NOT NULL ,
result decimal(10,0) NOT NULL,
tally_sum int(11) NOT NULL,
running_sum int(11) NOT NULL,
per_value decimal(10,2) NOT NULL
) TYPE=INNODB;
";

$result = mysql_query($schedule)
or die(mysql_error());
 
Back
Top