Jump to content

Permitting Special Characters in MySQL tablenames


ArizonaJohn

Recommended Posts

Hello,

 

I would like to allow users to add tables to my database with special characters in the table names.  The characters I would like to allow include #, &, *, and +.

 

Below is my code which allows the users to create tables, and the name is the variable "$name".  How can I allow them to use special characters for the table names?

 

Thanks in advance,

 

John

 

if (isset($_POST['name']) && !empty($_POST['name'])) {
mysql_connect("mysqlv10", "username", "password") or
die(mysql_error());
mysql_select_db("database") or die(mysql_error());

$table = mysql_real_escape_string($_POST['name']);

$query = "CREATE TABLE `$table` (id INT(11) NOT NULL auto_increment, site VARCHAR(150) NOT NULL, votes_up BIGINT(9) NOT NULL, votes_down BIGINT(9) NOT NULL, PRIMARY KEY(id), UNIQUE (site))";

 

http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

 

"Certain objects within MySQL, including database, table, index, column, alias, view, stored procedure, partition, and other object names are known as identifiers. This section describes the allowable syntax for identifiers in MySQL. Section 8.2.2, “Identifier Case Sensitivity”, describes which types of identifiers are case sensitive and under what conditions."

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.