create a table with a space, or funny character.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

create a table with a space, or funny character.

Post by lizlazloz »

hi, my website allwos users to create MySQL tables to store their info on. using a SQL command like this:

Code: Select all

create table thetable (name VARCHAR( 16 ) , rank TINYINT( 1 ) , UNIQUE ( name ) )
however, if they want the table name to be soemthing with a space, or a "'" for example, it wont work. how can i fix this???

btw, i am doing this through php and only showing the SQL command that is genereated...
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

i don't think the **sql can handle tables that have spaces...

You can work around like this:

Code: Select all

<?php
eregi_replace(" ","_", $query);
?>
that way you will rip any spaces and make them "_" so that your tables can be created :wink:
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

why do you need to use tables with ", spaces or anything like that?
just use characters, _ (underlines) and maybe some numbers? isn't that enough?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Basically you need to validate the type of information being submitted by your users. You definitely should not be plugging anything they submit straight into an SQL query. You need to define rules for what is an acceptable table name and then test the inputted data against that - then if the user is trying to use non alphanumeric characters or spaces, give them an error and get them to try again.

Mac
Post Reply