Reputation: 938
I was trying to create a table with a column names "Change". Here's the code I used
$create=mysql_query("CREATE TABLE table_name (ID int NOT NULL AUTO_INCREMENT KEY,
Name TEXT ,Property TEXT ,Change TEXT ,Change_Percent TEXT ,Low_Look TEXT ,
High_Look TEXT ,Low_Proximity TEXT ,Time_Index TEXT ,carom TEXT ,qualification
TEXT)");
// Execute query
if (mysql_query($con,$create))
{
echo "Table created successfully";
}
else
{
echo "Error creating table: " . mysql_error($conn);
}
This then gives me the following error
Warning: mysql_query() expects parameter 2 to be resource, boolean given in
C:\xampp\htdocs\stock\test.php on line 20
Error creating table: 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
'Change TEXT ,Change_Percent TEXT ,Low_Look TEXT ,High_Look TEXT ,Low_Proximity TEXT '
at line 1
After trying a few things I noticed that taking of the "e" from Change solved the problem. Now what could be causing it, and is there a way to name a column "Change"? if it were to be absolutely necessary.
Upvotes: 0
Views: 49
Reputation: 17511
Change is a reserved word. You might try changing to another name or at least wrapping it in backticks.
Upvotes: 1