Page 1 of 1

create a table with a space, or funny character.

Posted: Sun Jan 18, 2004 2:39 pm
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...

Posted: Sun Jan 18, 2004 2:56 pm
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:

Posted: Sun Jan 18, 2004 3:05 pm
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?

Posted: Mon Jan 19, 2004 4:49 am
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