muzammil1 Posted April 12, 2011 Share Posted April 12, 2011 <html> <head> </head> <body> <form name="register" action="create.php" method="post"> username:<input type="text" name="user" /> e-mail:<input type="text" name="email" /> <input type="submit" name="submit" value="register" /> </form> </body> </html> <?php //create.php $u=$_POST['user']; $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } if (mysql_query("CREATE TABLE '$u'",$con)) { echo "Database created"; } else { echo "Error creating database: " . mysql_error(); } mysql_close($con); ?> I am trying to create the table with a table name, and table name should be the one that is username. IS it possible? am i using the correct syntax???? Link to comment https://forums.phpfreaks.com/topic/233475-can-i-get-table-name-from-form/ Share on other sites More sharing options...
spiderwell Posted April 12, 2011 Share Posted April 12, 2011 it should work if you replace the '' around the variable in the sql with `` Link to comment https://forums.phpfreaks.com/topic/233475-can-i-get-table-name-from-form/#findComment-1200511 Share on other sites More sharing options...
muzammil1 Posted April 12, 2011 Author Share Posted April 12, 2011 I am sorry I did not get it Please bear with me i am newbie Link to comment https://forums.phpfreaks.com/topic/233475-can-i-get-table-name-from-form/#findComment-1200516 Share on other sites More sharing options...
muzammil1 Posted April 12, 2011 Author Share Posted April 12, 2011 do u mean i shoul put ' ' around $u yes i have already done that, its not working. Link to comment https://forums.phpfreaks.com/topic/233475-can-i-get-table-name-from-form/#findComment-1200521 Share on other sites More sharing options...
dcro2 Posted April 12, 2011 Share Posted April 12, 2011 No, instead of single quotes put backticks like this: ` if (mysql_query("CREATE TABLE `$u`",$con)) Link to comment https://forums.phpfreaks.com/topic/233475-can-i-get-table-name-from-form/#findComment-1200543 Share on other sites More sharing options...
muzammil1 Posted April 13, 2011 Author Share Posted April 13, 2011 thanks a lot. yea it worked. Million thanks Link to comment https://forums.phpfreaks.com/topic/233475-can-i-get-table-name-from-form/#findComment-1200989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.