Creating tables with PHP script, getting MySQL errors
Posted by:
Don Hanson
Date: December 14, 2005 01:30AM
I keep getting this error when attampting to create a table with a simple PHP script I whipped up.
Invalid query: 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 'INDEX, talent_step VARCHAR, action BOOLEAN, karma BOOLEAN, skill BOOLEAN, skill_' at line 1
Whole query: CREATE TABLE IF NOT EXISTS talents (id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, talent_name VARCHAR INDEX, talent_step VARCHAR, action BOOLEAN, karma BOOLEAN, skill BOOLEAN, skill_only BOOLEAN, skill_cat VARCHAR, strain TINYINT UNSIGNED, source VARCHAR, description TEXT)
I've tried changing names of tables, puting the in single quotes, changing column types and a few other things but nothing seems to change the fact that it errors out right after the second column definition (talent_name)
Here is the PHP code that creates the query
### talents table
$talqry = "CREATE TABLE IF NOT EXISTS talents (";
$talqry .= "id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, ";
$talqry .= "talent_name VARCHAR INDEX, ";
$talqry .= "talent_step VARCHAR, ";
$talqry .= "action BOOLEAN, ";
$talqry .= "karma BOOLEAN, ";
$talqry .= "skill BOOLEAN, ";
$talqry .= "skill_only BOOLEAN, ";
$talqry .= "skill_cat VARCHAR, ";
$talqry .= "strain TINYINT UNSIGNED, ";
$talqry .= "source VARCHAR, ";
$talqry .= "description TEXT)";
$talres = mysql_query($talqry);
if (!$talres) {
$message = 'Invalid query: ' . mysql_error() . "<BR><BR>\n\n";
$message .= 'Whole query: ' . $talqry . "<BR><BR>\n\n";
die($message);
}
I've tried changing the double quotes " to single quotes ' in the variable declarations as well. This has had me stumped for a while and is probabley some very simple mistake I'm missing.