Jump to content

Creating multiple tables using the same form. (?)


XJTRy

Recommended Posts

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';

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.