473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Permitting Special Characters in MySQL tablenames

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

Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['name']) && !empty($_POST['name'])) {
  2. mysql_connect("mysqlv10", "username", "password") or
  3. die(mysql_error());
  4. mysql_select_db("database") or die(mysql_error());
  5.  
  6. $table = mysql_real_escape_string($_POST['name']);
  7.  
  8. $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))";
Jun 8 '09 #1
1 4179
Atli
5,058 Expert 4TB
Hi.

That query should work fine.
If you enclose the table name is back-ticks (`), you can safely put special characters into it.

For example:
Expand|Select|Wrap|Line Numbers
  1. mysql> CREATE TABLE `#&*+`(id serial primary key);
  2. Query OK, 0 rows affected (0.03 sec)
  3.  
  4. mysql> INSERT INTO `#&*+` VALUES (),(),();
  5. Query OK, 3 rows affected (0.00 sec)
  6. Records: 3  Duplicates: 0  Warnings: 0
  7.  
  8. mysql> SELECT * FROM `#&*+`;
  9. +----+
  10. | id |
  11. +----+
  12. |  1 |
  13. |  2 |
  14. |  3 |
  15. +----+
  16. 3 rows in set (0.00 sec)
There are some limitations to this tho.
See 8.2. Schema Object Names for details on what is allowed.
Jun 8 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Mosher | last post by:
Hi all, I have an issue with php and/or mysql. I have a php form that writes "items" to a mysql database, including a description of the item. On the mysql server, "magic_quotes_gpc" is ON. I...
3
by: Ruby Tuesday | last post by:
How do I transfer my MS Access DB to MySQL? One issue though, in Access I have some special character such fraction, backquote, etc ... how do I replace those characters to ASCI equivalent...
4
by: Ewok | last post by:
let me just say. it's not by choice but im dealing with a .net web app (top down approach with VB and a MySQL database) sigh..... Anyhow, I've just about got all the kinks worked out but I am...
25
by: Wim Cossement | last post by:
Hello, I was wondering if there are a few good pages and/or examples on how to process form data correctly for putting it in a MySQL DB. Since I'm not used to using PHP a lot, I already found...
1
by: ronrsr | last post by:
I have an MySQL database called zingers. The structure is: zid - integer, key, autoincrement keyword - varchar citation - text quotation - text I am having trouble storing text, as typed in...
1
by: ronrsr | last post by:
I have an MySQL database called zingers. The structure is: zid - integer, key, autoincrement keyword - varchar citation - text quotation - text I am having trouble storing text, as typed in...
6
by: TheRealDan | last post by:
Hi all. I'm having a problem with a special characters. I have php script that reads from an xml file and writes to a mysql db. It's a script called phptunest that I found on the net, although the...
2
by: thisisazam | last post by:
Hi I am picking records from xml file and saving them into mysql database. I am When I insert records, the special characters like ö,å,ä are being transformed into some unwanted values. I tried to...
2
by: matech | last post by:
I have a problem with uploading special characters from excel files to mysql 5. It doesn't matter if I use UTF-8 or iso-8859-1 when uploading the trademark ™ symbol. htmlspecialchars() or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.