anargi Posted February 6, 2012 Share Posted February 6, 2012 Hi! I have a question about (dynamic)create table with php script.I don't know if (dynamic) is correct word. I want to create a mysql table but the name of table if it is possible the user to give via html form. my example: This is simple html form where the user he can to insert two fields(id,name) <html> <head> </head> <body> <meta http-equiv="Content-Language"content="en-us-gr"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <form method="POST" action="categ.php"> <table border="1"> <tr><td> <div align="right"> ID: <input type="text" name="id" size="19"> </div> <div align="right"> Name: <input type="text" name="name" size="19"> </div> <div align="right"> <input type="Submit" name="Create" value="create"> </div> </tr></tr> </table> </body> </head> These data send in my database via below code: <?php mysql_connect("localhost","root","MYPASSWORD") or die(mysql_error()); if(mysql_select_db("blog")); { mysql_query("SET NAMES 'utf8'"); } $sql="INSERT INTO menu(id,name) VALUES ('$_POST[id]','$_POST[name]')"; mysql_query($sql); { echo "ok!"; } ///////////////////////////////////////////////////////////////////////////////////// //[b]And here i want to create a table but the name of table if it is possible to be the name where the user gave via above html form.[/b] $qry=mysql_query("CREATE TABLE /*The name of the table via above html form*/ (mycode...mpla...mpla)"); if(!$qry) { die("Table not created\n".mysql_error()); } else { echo "Table Created\n"; } ?> <meta http-equiv="refresh" content="3;url=admin_home.php"> Is there some way to success this result? Thanks! Quote Link to comment Share on other sites More sharing options...
mikosiko Posted February 7, 2012 Share Posted February 7, 2012 I have a question about (dynamic)create table with php script why do you want to do that? Quote Link to comment Share on other sites More sharing options...
kickstart Posted February 7, 2012 Share Posted February 7, 2012 Hi Creating / modifying tables in that way is fairly easy. Just use a create statement as you have suggested, but changing the table name. However from a design point of view it is a really bad idea and will result in a quite horrible database, making it very difficult to extract data from it. All the best Keith 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.