Perigoso Posted July 17, 2007 Share Posted July 17, 2007 Hi there guys I'm having a problem witch i can't solve, i would like anyone to help me out. I have this code. <?php $fp = fopen("fod.txt", "r"); $ler2=fread($fp,8092); fclose($fp); $f= unserialize($ler2); $dbhost='localhost'; $dbusername='root'; $dbname='apa'; $link_id = mysql_connect ($dbhost, $dbusername); if (!mysql_select_db($dbname)) die(mysql_error()); $result= "CREATE TABLE $f (id int(5) auto_increment, matprima char(30),fornecedor char(100), qld char(15), gran char(10), peso char(10),horas char(50),qtdent char(20),cod char(100), PRIMARY KEY (id))"; if (mysql_query($result)){ print ("<p><h3 align=center>Table created...</h3></p>"); mysql_close($link_id); } The problem is on the $f variable.If it has the value of "tom", the table can be created, if it has the value of "tom jones" i canot create it. Is it because of the space in between? Is there another way? Thanks Quote Link to comment Share on other sites More sharing options...
paul2463 Posted July 17, 2007 Share Posted July 17, 2007 you are right the problem is the space between tom and jones, you cannot have a table name with spaces in it. you can write yourself a little function that removes spaces and replaces it with an underscore <?php function createTableName($text) { return str_replace(" ", "_", $text);//replaces spaces with an underscore } $fold= unserialize($ler2);//f old $fnew = createTableName($fold);//f new. then use $fnew instead of $f in your query ?> Quote Link to comment Share on other sites More sharing options...
Perigoso Posted July 17, 2007 Author Share Posted July 17, 2007 thanks a lot!! Problem solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.