Concatenation Create Table

Asked

Viewed 72 times

0

I’m trying to create a table from the user’s email, and I’m using the code below:

 $email = $_SESSION["email"];
 echo $email;
 $create=mysql_query("CREATE TABLE userpics_'$email' (id_user VARCHAR(60), id_pic VARCHAR(200), id_tipo INT(2))");
        if (mysql_query($create))
        {
         echo "TABLE created.";
        }
        else 
        {
         echo "Error in CREATE TABLE.";
        }

If the user is the [email protected], the table name should be [email protected]. With this code, I receive the message "Error in CREATE TABLE." else. Can anyone tell me where I might be going wrong? Maybe it’s a syntax error.

  • 2

    It is probably because of the arroba(@) in the table name, try to use another form, no special characters.

  • @touchmx is right, that may be so. I will do some other tests with other type of information. Thank you.

  • 1

    mysql allows tables with "@". The problem is not that.

  • The character . is used to separate the database name from the table name. I think this is creating a confusion. Use quoted Dentifiers (name between crases).

1 answer

2

Rewrite create by adding English quotes ` between the table name. You can do so:

$create = mysql_query("CREATE TABLE `userpics_".$email."`(  
                            `id_user` VARCHAR(60),
                            `id_pic` VARCHAR(200),
                            `id_tipo` INT(2)
                        );"
);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.