HELP! - Creating MySQL Tables

Discussion in 'PHP' started by jorgy, Apr 18, 2009.

  1. #1
    I'm trying to write a script that will create a few MYSQL tables. The code below is where my problem is, I think. When run, the first table is created, but not the second two. I'm thinking this means I'm connecting to the MySQL db correctly, and maybe there's a syntax error I'm missing? Can someone comb through this for me, it's driving me nuts! Thanks for any help!

    
    $con = mysql_connect($servername, $username, $password);
    if (!$con)	{
      die('You didn\'t enter the correct information for your MySQL server (username, password, and/or servername). Please go back and try again!');
      }
    
    mysql_select_db($dbname, $con);
    
    $create_games = mysql_query("CREATE TABLE games(id INT NOT NULL AUTO_INCREMENT ,name TEXT NOT NULL ,embed INT NOT NULL DEFAULT 0,embed_code TEXT NOT NULL ,swf TEXT NOT NULL ,description TEXT NOT NULL ,plays INT NOT NULL DEFAULT 0 ,num_ratings INT NOT NULL ,rating DECIMAL NOT NULL ,PRIMARY KEY ( id ) ,INDEX ( id )) ENGINE = MYISAM");
    $create_settings = mysql_query("CREATE TABLE settings(id INT NOT NULL AUTO INCREMENT ,title TEXT NOT NULL ,name TEXT NOT NULL ,name_img INT NOT NULL DEFAULT 0,name_url TEXT NOT NULL ,description TEXT NOT NULL ,bg_color TEXT NOT NULL ,link_color TEXT NOT NULL ,url_style TEXT NOT NULL ,stylesheet TEXT NOT NULL ,index_code TEXT NOT NULL ,footer_code TEXT NOT NULL ,game_code TEXT NOT NULL ,navbar_code TEXT NOT NULL ,category_code TEXT NOT NULL , mysql_user TEXT NOT NULL, db_name TEXT NOT NULL, servername TEXT NOT NULL, mysql_password TEXT NOT NULL, INDEX ( id )) ENGINE = MYISAM"); 
    $create_categories = mysql_query("CREATE TABLE categories(id INT NOT NULL AUTO INCREMENT, order INT NOT NULL, name TEXT NOT NULL, num_games INT NOT NULL, INDEX(id)) ENGINE = MYISAM");
    
    
    PHP:
     
    jorgy, Apr 18, 2009 IP
  2. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #2
    Add this at the top of all your code ( you'll see what's wrong with your queries/code ):
    error_reporting(E_ALL);
    PHP:
     
    ActiveFrost, Apr 18, 2009 IP
    jorgy likes this.
  3. jorgy

    jorgy Peon

    Messages:
    611
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Answered my own question!

    Should someone ever stumble upon this with the same problem, my error was that I had fat fingered:

    AUTO INCREMENT instead of AUTO_INCREMENT for the latter two tables
     
    jorgy, Apr 18, 2009 IP