Results 1 to 10 of 10

Thread: Creating an sql table error

  1. #1
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default Creating an sql table error

    PHP Code:
    CREATE TABLE `messages` (
    `
    idINT11 NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `
    titleVARCHAR255 NULL 
    `messageTEXT NOT NULL ,
    `
    fromINT11 NOT NULL ,
    `
    toINT11 NOT NULL ,
    `
    from_viewedBOOL NOT NULL DEFAULT '0',
    `
    to_viewedBOOL NOT NULL DEFAULT '0',
    `
    from_deletedBOOL NOT NULL DEFAULT '0',
    `
    to_deletedBOOL NOT NULL DEFAULT '0',
    `
    from_vdateDATETIME NULL ,
    `
    to_vdateDATETIME NULL ,
    `
    from_ddateDATETIME NULL ,
    `
    to_ddateDATETIME NULL ,
    `
    createdDATETIME NOT NULL
    ENGINE MYISAM 
    This code is causing an error. Any help

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Why not tell us what the error is?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    I already spotted the error myself. It's a syntax error, you forgot a comma after '`message` TEXT NOT NULL '.

    This should work:
    Code:
    CREATE TABLE `messages` (
    `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `title` VARCHAR( 255 ) NULL ,
    `message` TEXT NOT NULL ,
    `from` INT( 11 ) NOT NULL ,
    `to` INT( 11 ) NOT NULL ,
    `from_viewed` BOOL NOT NULL DEFAULT '0',
    `to_viewed` BOOL NOT NULL DEFAULT '0',
    `from_deleted` BOOL NOT NULL DEFAULT '0',
    `to_deleted` BOOL NOT NULL DEFAULT '0',
    `from_vdate` DATETIME NULL ,
    `to_vdate` DATETIME NULL ,
    `from_ddate` DATETIME NULL ,
    `to_ddate` DATETIME NULL ,
    `created` DATETIME NOT NULL
    ) ENGINE = MYISAM ;
    - Josh

  4. #4
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Hi everyone,

    PHP Code:
    CREATE TABLE pmsys(
    id INT NOT NULL AUTO_INCREMENT,
    PRIMARY KEY(id),
    to VARCHAR(30),
    from VARCHAR(32),
    title VARCHAR(32),
    message VARCHAR(250),
    date VARCHAR(30),
    ifread VARCHAR(30)) 
    #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 'to VARCHAR(30), from VARCHAR(32), title VARCHAR(32), message VARCHAR(250), d' at line 4


    Any help

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Read JShor's message. Did that not fix it?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    The code I just posted is a differnet one

  7. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    from is a reserved word (it's a SQL command). It is always good practice to escape table names, column names, etc. using backticks. sql doesn't automatically know that the name you write is a name; it is only after checking it against possible commands/keywords (and finding it doesn't match) that it decides to treat it as a value. this is good for forward-compatibility as well. for example:
    Code:
    CREATE TABLE `pmsys`( 
    `id` INT NOT NULL AUTO_INCREMENT, 
    PRIMARY KEY(`id`), 
    `to` VARCHAR(30), 
    `from` VARCHAR(32), 
    `title` VARCHAR(32), 
    `message` VARCHAR(250), 
    `date` VARCHAR(30), 
    `ifread` VARCHAR(30))
    note that these are backticks ( ` ), not single-quotes ( ' ).

  8. #8
    Join Date
    Aug 2011
    Location
    HCM
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    keyboard1333 didn't show clearly what the error you spotted, so i can't know it exactly. But, i think maybe problem in here is your table name "messages". In past, i used to create tables with some popular name, unfortunately it duplicate with same system name were create before. It can made wrong understand and error here.
    Can you try another table name? Maybe it works.

  9. #9
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by keyboard1333 View Post
    PHP Code:
    CREATE TABLE `messages` (
    `
    idINT11 NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `
    titleVARCHAR255 NULL 
    `messageTEXT NOT NULL ,
    `
    fromINT11 NOT NULL ,
    `
    toINT11 NOT NULL ,
    `
    from_viewedBOOL NOT NULL DEFAULT '0',
    `
    to_viewedBOOL NOT NULL DEFAULT '0',
    `
    from_deletedBOOL NOT NULL DEFAULT '0',
    `
    to_deletedBOOL NOT NULL DEFAULT '0',
    `
    from_vdateDATETIME NULL ,
    `
    to_vdateDATETIME NULL ,
    `
    from_ddateDATETIME NULL ,
    `
    to_ddateDATETIME NULL ,
    `
    createdDATETIME NOT NULL
    ENGINE MYISAM 
    This code is causing an error. Any help

    If you will right what is the error its showing will more helpful to solve your problem.

  10. #10
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Quote Originally Posted by jimmy1 View Post
    If you will right what is the error its showing will more helpful to solve your problem.
    This issue was already resolved. It was a visible syntax error.
    - Josh

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •