What is wrong with this MySQL?

Discussion in 'Web Design and Development' started by tominated, Feb 10, 2007.

  1. tominated macrumors 68000

    tominated

    Joined:
    Jul 7, 2006
    Location:
    Queensland, Australia
    #1
    I am trying to make anther forum, from another tutorial for my site. I am trying to do it using MAMP, but when i put in the mysql query:
    Code:
     CREATE TABLE posts (
       ID int(5) DEFAULT '0' NOT NULL auto_increment,
       TopicID int(5) DEFAULT '0' NOT NULL,
       Name varchar(50) NOT NULL,
       Email varchar(50) NOT NULL,
       Password varchar(50) NOT NULL,
       TimeStamp varchar(10) NOT NULL,
       Post text NOT NULL,
       PRIMARY KEY (ID)
    );
    
    CREATE TABLE topics (
       ID int(5) DEFAULT '0' NOT NULL auto_increment,
       TopicName varchar(50) NOT NULL,
       PRIMARY KEY (ID)
    );
    I comes up with an error saying
    The tut is here.
    does anybody know what is going on?
     
  2. Mitthrawnuruodo Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #2
    Looks ok... the only thing I can think of is that tou try to remove the little 's:

    PHP:
    ID int(5) DEFAULT 0 NOT NULL auto_increment
    I've encountered the odd version of phpMyAdmin that has refused to accept my queries before I removed a lot of those...

    Edit: Also it doesn't make much sense to say the default is 0 on autoincremented IDs...
     
  3. tominated thread starter macrumors 68000

    tominated

    Joined:
    Jul 7, 2006
    Location:
    Queensland, Australia
    #3
    could you show me what you mean by changing the whole bit of code please?;)
     
  4. Mitthrawnuruodo Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #4
    Try something like this:
    PHP:
     CREATE TABLE posts (
       
    ID int(5NOT NULL auto_increment,
       
    TopicID int(5NOT NULL DEFAULT 0,
       
    Name varchar(50NOT NULL,
       
    Email varchar(50NOT NULL,
       
    Password varchar(50NOT NULL,
       
    TimeStamp varchar(10NOT NULL,
       
    Post text NOT NULL,
       
    PRIMARY KEY (ID)
    TYPE=MyISAM;

    CREATE TABLE topics (
       
    ID int(5NOT NULL auto_increment,
       
    TopicName varchar(50NOT NULL,
       
    PRIMARY KEY (ID)
    TYPE=MyISAM;
    And let us know which error that causes... :p ;)
     
  5. colocolo macrumors 6502

    Joined:
    Jan 17, 2002
    Location:
    Santiago, Chile
    #5
    I've never put a default value for an auto increment; the whole point of it is that the DB automatically sets its value, so there is no default one. Try eliminating that part :)

    On a side note, if you plan on making your database portable, try to find a way around intead of using auto increments. They present two problems; the way of handling the last value (I've had issues in PHP+mysql when the last value is returned false in some obscure circumstances), and also I think its easier to just lock the table, find the max number and increment it by one, so you can just port it to Oracle or your database of choice at a later time with less hassle (eg you dont have access to create sequences and triggers).

    Let us know if that was the issue, and good luck!
     
  6. tominated thread starter macrumors 68000

    tominated

    Joined:
    Jul 7, 2006
    Location:
    Queensland, Australia
    #6
    ummmm..... yes.... did you read that i was following a tutorial?
    BTW: What Mitthrawnuruodo said to do worked, but when i try to make a topic it aint working. Don't bother. I'll probably just find a way to integrate vanilla or phorum
     
  7. colocolo macrumors 6502

    Joined:
    Jan 17, 2002
    Location:
    Santiago, Chile
    #7
    Yes, and I also read you were looking for a solution.

    Mitthrawnruodo's solution implied basically the same thing; he also eliminated the default value from the auto_increment. I just happenned to bore you more with my explanation, it seems :)
     

Share This Page