bamfon Posted January 8, 2011 Share Posted January 8, 2011 Hi, i was wondering how i could make it so that when it makes a table, it names the table the name you put in the text field so far i got this <label for="name"></label> <input type="text" name="name" id="name"> <?php include"/config.php"; ?> <?php $conn = database_connect(); $sql = 'CREATE TABLE `zones` ( `zid` TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT, `zdesc` VARCHAR( 150 ) NOT NULL, `zwidth` SMALLINT( 3 ) DEFAULT 0 NOT NULL, `zheight` SMALLINT( 3 ) DEFAULT 0 NOT NULL, `zmax` MEDIUMINT(7) unsigned NOT NULL default 12288, PRIMARY KEY ( `zid` ) )'; echo 'Creating table: \'zones\'....'; error_reporting(E_ALL); ini_set('display_errors', '1'); ?> right now it will make a table called zones I want to make it so that if i put "him" or anything else in the text field it will name the table what it says in the text box, when it ceate the table. Link to comment https://forums.phpfreaks.com/topic/223755-php-sql-table-help/ Share on other sites More sharing options...
bamfon Posted January 8, 2011 Author Share Posted January 8, 2011 so far i got <form name="form1" method="post" action="trying.php"> <input type="text" name="name" id="name"> <input type="submit" value="Submit"> <?php include "./config.php"; ?> <?php $name = $_POST['name']; $conn = database_connect(); $sql = 'CREATE TABLE `'.$_POST['name'].'` ( `zid` TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT, `zdesc` VARCHAR( 150 ) NOT NULL, `zwidth` SMALLINT( 3 ) DEFAULT 0 NOT NULL, `zheight` SMALLINT( 3 ) DEFAULT 0 NOT NULL, `zmax` MEDIUMINT(7) unsigned NOT NULL default 12288, PRIMARY KEY ( `zid` ) )'; error_reporting(E_ALL); ini_set('display_errors', '1'); ?> </form> dont seem to be working Link to comment https://forums.phpfreaks.com/topic/223755-php-sql-table-help/#findComment-1156591 Share on other sites More sharing options...
bamfon Posted January 8, 2011 Author Share Posted January 8, 2011 fixed it <form method="POST" action=""> <input type="text" name="name" id="name"> <input type="submit" value="Submit"> </form> <?php include "./config.php"; ?> <?php if(isset($_POST['name'])) { $conn = database_connect(); $sql = 'CREATE TABLE `'.$_POST['name'].'` ( `zid` TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT, `zdesc` VARCHAR( 150 ) NOT NULL, `zwidth` SMALLINT( 3 ) DEFAULT 0 NOT NULL, `zheight` SMALLINT( 3 ) DEFAULT 0 NOT NULL, `zmax` MEDIUMINT(7) unsigned NOT NULL default 12288, PRIMARY KEY ( `zid` ) )'; mysql_query($sql) or die(mysql_error()); error_reporting(E_ALL); ini_set('display_errors', '1'); } ?> Link to comment https://forums.phpfreaks.com/topic/223755-php-sql-table-help/#findComment-1156594 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.