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 Link to comment https://forums.phpfreaks.com/topic/60447-problem-creating-a-table-on-mysql-with-php/ 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 ?> Link to comment https://forums.phpfreaks.com/topic/60447-problem-creating-a-table-on-mysql-with-php/#findComment-300682 Share on other sites More sharing options...
Perigoso Posted July 17, 2007 Author Share Posted July 17, 2007 thanks a lot!! Problem solved Link to comment https://forums.phpfreaks.com/topic/60447-problem-creating-a-table-on-mysql-with-php/#findComment-300685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.