Could anyone tell me if they find anything wrong with this code? It's a script to install my message board system. I get the error: "Gravity Board X experienced an error while trying to create the boards table."

<?php

if ($password == $passwordconfirm) {

##MySQL Connect

mysql_connect($hostname,$username,$password) OR DIE("Gravity Board X experienced an error while trying to connect to your MySQL database.");

##Select the MySQL Database

mysql_select_db($dbname) OR DIE ("Gravity Board X was unable to select the proper database.");

##Create the MySQL tables needed to run GBX

mysql_query("CREATE TABLE " . $prefix . "boards (name VARCHAR(255), description TEXT, board_id INT UNSIGNED NOT NULL AUTO_INCREMENT, cat_id TINYINT DEFAULT '1', boardorder INT)") OR DIE("Gravity Board X experienced an error while trying to create the boards table.");

mysql_query("CREATE TABLE " . $prefix . "categories (catname TINYTEXT, cat_id INT UNSIGNED NOT NULL AUTO_INCREMENT, catorder INT)") OR Die ("Gravity Board X experienced an error while trying to create the categories table.");

mysql_query("CREATE TABLE " . $prefix . "ims (message TEXT, subject TINYTEXT, date TIMESTAMP DEFAULT '00/00/0000 00:00:00', reply TINYTEXT, replytime DATETIME, from TINYINT, to TINYINT, imid INT AUTO_INCREMENT)") OR DIE ("Gravity Board X experienced an error while trying to create the IMs table.");

mysql_query("CREATE TABLE " . $prefix . "membergroups (group_id TINYINT, group_name TINYTEXT, group_type TINYTEXT)") OR DIE ("Gravity Board X experienced an error while trying to create the member groups table.");

mysql_query("CREATE TABLE " . $prefix . "members (memberid INT UNSIGNED NOT NULL AUTO_INCREMENT, username VARCHAR(255), displayname TINYTEXT, realname TINYTEXT, password TINYTEXT, email TINYTEXT, postcount INT DEFAULT '0', signature TINYTEXT, user_text TINYTEXT, aim_id TINYTEXT, yahoo_id TINYTEXT, msn_id TINYTEXT, icq_id TINYTEXT, homepage TINYTEXT, homepage_link TINYTEXT, memberGroup INT, birthdate DATE, location TINYTEXT, dateregistered DATETIME)") OR DIE("Gravity Board X experienced an error while trying to create the users table.");

mysql_query("CREATE TABLE " . $prefix . "messages (id smallint(5) unsigned DEFAULT '' NOT NULL auto_increment,new char(3)  DEFAULT 'Yes', ToUser INT(20), FromUser INT(20) ,subject TEXT  DEFAULT '' NOT NULL ,timestamp DATETIME  DEFAULT '00/00/0000 00:00:00' NOT NULL ,body text  DEFAULT '' NOT NULL)") OR DIE ("Gravity Board X experienced an error while trying to create the messages table.");

mysql_query("CREATE TABLE " . $prefix . "news (gbxnews TEXT, newsid TINYINT DEFAULT '1')") OR DIE ("Gravity Board X experienced an error while trying to create the news table.");

mysql_query("CREATE TABLE " . $prefix . "posts (subject VARCHAR(255), dateposted DATETIME, thread_id TINYINT, msg_id INT(15) UNSIGNED NOT NULL AUTO_INCREMENT, message TEXT, poster_email TINYTEXT, userID INT)") OR DIE("Gravity Board X experienced an error while trying to create the posts table.");

mysql_query("CREATE TABLE " . $prefix . "settings (regemail TEXT, background TINYTEXT, textcolor TINYTEXT, linkcolor TINYTEXT, vlinkcolor TINYTEXT, alinkcolor TINYTEXT, hovercolor TINYTEXT, boxbgcolor TINYTEXT, boxtextcolor TINYTEXT)") OR DIE ("Gravity Board X experienced an error while trying to create the settings table.");

mysql_query("CREATE TABLE " . $prefix . "threads (thread_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, first_msg INT, board_id TINYINT, view_num TINYINT DEFAULT '0', reply_num TINYINT DEFAULT '0', sticky TINYTEXT DEFAULT 'no', locked TINYTEXT DEFAULT 'no', last_msg_time DATETIME)") OR DIE("Gravity Board X experienced an error while trying to create the threads table.");

##Create the first Administrator account

mysql_query("INSERT INTO " . $prefix . "users (username, displayname, password, email, membergroup) VALUES ('admin', '$boardname Administrator', 'admin', 'Administrator', 'Administrator')", $connection) OR DIE("Gravity Board X experienced an error while trying to create the first Administrator account.");

##Create the first General Discussion (Default) category

mysql_query("INSERT INTO " . $prefix . "categories (catname, cat_order) VALUES ('General Discussion (Default)', '1')", $connection) OR DIE ("Gravity Board X experienced an error while trying to create the General Discussion (Default) board.");

##Set default news

mysql_query("INSERT INTO " . $prefix . "news (gbxnews) VALUES ('Welcome To Gravity Board X!')", $connection) OR DIE ("Gravity Board X experienced an error while trying to set the default news.");

##Set default Settings

mysql_query("INSERT INTO " . $prefix . "settings (background, textcolor, linkcolor, vlinkcolor, alinkcolor, hovercolor) VALUES ('#FFFFFF','#000000','#0000FF','#FF0000','#FF0000','#FF0000')", $connection) OR DIE ("Gravity Board X was unable to create the default settings.");

##Close MySQL connection

mysql_close();

##Create the board SQL configuration file
$filepointer = fopen("config.inc", "w");
fputs($filepointer, '<? $hostname="' . $hostname . "\";\r\n");
fputs($filepointer, '$prefix="' . $prefix . "\";\r\n");
fputs($filepointer, '$username="' . $username . "\";\r\n");
fputs($filepointer, '$password="' . $password . "\";\r\n");
fputs($filepointer, '$dbname="' . $dbname . "\";\r\n");
fputs($filepointer, '$boardname="' . $boardname . "\";\r\n");
fputs($filepointer, "function dbconnect(){global \$hostname;global \$username;global \$password;global \$dbname;\$connection = MYSQL_CONNECT(\$hostname,\$username,\$password) OR DIE(\"Gravity Board X was unable to connect to the specified database. Please go back and double-check the database you supplied.\");\r\n @mysql_select_db(\"\$dbname\") OR DIE(\"Gravity Board X was able to connect to your SQL host, but had difficulties selecting the specified database.  Please go back and double-check the database you supplied.\");\r\n return \$connection;}?>");
fclose($filepointer);

echo "Congratulations, your Gravity Board X has been successfully installed!  You may now login with the username \"admin\" and the password \"admin\".  It is highly reccommended that you change the password to this account.  To get started, enter your admin control panel and create a board.";

} else {

echo "Your passwords supplied did not match. Please go back and re-enter your data.";

}

?>

    I think AUTO_INCREMENT fields cannot be second... there must be first in each table and also be Indexed

    For example in the table categories you have an Auto Increment field called cat_id but it is second instead of first

    If this is not your script the best thing to do is contact the authors and ask them about this issue with the Auto Increment fields,
    otherwise put the fields containing "AUTO_INCREMENT" first in their field declarations.

      Yes, this is my script... A newer version of it. The older version had the AUTO_INCRIMENT fields where they are now, and it worked properly... But its the first table being created (the boards table) it is having trouble with...

        cool 😉

        but make a trial with the auto increments as first ... I think its going to work fine

          I copied and pasted your query into my mysql client and it complained that there's no key defined.

          This is the exact error message:

          ERROR 1075: Incorrect table definition; There can only be one auto column and it
          must be defined as a key

          Next time, instead of just die()'ing, try outputting mysql_error() to see what the error is.

          Diego

            I see that the 'OR DIE' is in all caps. Isn't PHP case-sensitive? And when creating your categories table, 'OR DIE' is in partial caps. i.e. 'OR Die'.

              PHP variables are case-sensitive, but PHP functions are not. That's why sometimes you see people use setcookie(), and some other people use setCookie(). It's the same function for PHP. I'm not sure about PHP operators, like OR, but I guess they are case-insensitive, too.

              Diego

                What do you mean they must be defined as a key?

                  Look up primary keys on the MySQL manual.

                  Diego

                    Write a Reply...