XJTRy Posted February 14, 2008 Share Posted February 14, 2008 The following insert is from a script that emails me information from an HTML form and creates a table in an mySQL database. Everything works correctly but I need to alter the script so that is uses a user defined text field ("user") to name the table created in the database. Without doing so I have the same table name ("contact") created time after time. Any help greatly appreciated! Here the excerpt: $query = 'SELECT DATABASE db233024213'; $result = mysql_query($query); mysql_select_db('db233024213') or die('Cannot select database'); $query = 'CREATE TABLE contact( '. 'id INT NOT NULL AUTO_INCREMENT, '. 'date VARCHAR(20) NOT NULL, '. 'acmod VARCHAR(50) NOT NULL, '. 'acid VARCHAR(30) NOT NULL, '. 'legs TEXT NOT NULL, '. 'route VARCHAR(20) NOT NULL, '. 'duration VARCHAR(50) NOT NULL, '. 'dl VARCHAR(30) NOT NULL, '. 'nl TEXT NOT NULL, '.'cname VARCHAR(20) NOT NULL, '. 'inst VARCHAR(50) NOT NULL, '. 'apps VARCHAR(30) NOT NULL, '. 'nite TEXT NOT NULL, '. 'xc VARCHAR(20) NOT NULL, '. 'pic VARCHAR(50) NOT NULL, '. 'dual VARCHAR(30) NOT NULL, '. 'remarks TEXT NOT NULL, '. 'PRIMARY KEY(cid))'; $result = mysql_query($query); include 'closedb.php'; Quote Link to comment Share on other sites More sharing options...
trq Posted February 14, 2008 Share Posted February 14, 2008 The first question I must ask is why are you creating multiple versions of what is essentually the same table? Quote Link to comment Share on other sites More sharing options...
XJTRy Posted February 14, 2008 Author Share Posted February 14, 2008 Each table will be created by an individual and hold their respective logbook. I want to name the tables based upon their employee id. At any time the person can download the data from their respective table (in Excel) because it's then imported into another application. Quote Link to comment Share on other sites More sharing options...
XJTRy Posted February 15, 2008 Author Share Posted February 15, 2008 I have not been in home in a few days to experiment with the script, just wondering if anyone has any suggested solutions. I should be able to apply suggestions this weekend. Thanks again. Quote Link to comment Share on other sites More sharing options...
XJTRy Posted February 16, 2008 Author Share Posted February 16, 2008 I have tried the following with no luck. Any suggestions? $query = 'SELECT DATABASE db233024213'; $result = mysql_query($query); $table = $_POST['user']; mysql_select_db("db233024213"); $query = "CREATE TABLE '$table' ( Id int(6) NOT NULL , Date varchar(15) NOT NULL, Acmod varchar(15) NOT NULL, Acid varchar(10) NOT NULL, Legs varchar(10) NOT NULL, Route varchar(30) NOT NULL, Duration varchar(10) NOT NULL, Dl varchar(15) NOT NULL, Nl varchar(10) NOT NULL )"; $result = mysql_query($query); 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.