Hello,

In PHP and mysql I am creating a script that adds a new event on the command of the administartor. Everything in the script works fine apart from the create table script. No table is created. I added a 'die' to the end of the query to show the mysql error and to check the table name is correct and this is what I get:

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 '{ 'memberID' INT NOT NULL, PRIMARY KEY(memberID), 'Name' VARCHAR(65), 'em' at line 2 CASPA10.

CASPA10 is the table name and is the right one.

Here is the code causing the problem:

$id="CASPA$idl";

$create="CREATE TABLE $id 
{ 
'memberID' INT NOT NULL, 
PRIMARY KEY(memberID),
'Name' VARCHAR(65), 
'email' VARCHAR(65) 
}";
$q=mysql_query($create) or die(mysql_error() . $id);

Any ideas?

Regards
James

    I believe it's the curly braces in your code. Try using parentheses instead. Also, you don't need to quote the column names:

    $create="CREATE TABLE $id
    (
    memberID INT NOT NULL,
    PRIMARY KEY(memberID),
    Name VARCHAR(65),
    email VARCHAR(65)
    );";

      As an addition to the previous post, while it's true that you generally don't need to quote field names, certain words can be used as fieldnames only if "quoted", except in mysql you don't encase them in quotes, you encase them in backticks `

        Write a Reply...