Jump to content

Creating Table from input


eugene2009

Recommended Posts

having a problem.. how can i create a table in a mysql database from a users input?

 

CREATE TABLE $tablename( '.
         'cid INT NOT NULL AUTO_INCREMENT, '.
         'cname VARCHAR(20) NOT NULL, '.
         'cemail VARCHAR(50) NOT NULL, '.
         'csubject VARCHAR(30) NOT NULL, '.
         'cmessage TEXT NOT NULL, '.
         'PRIMARY KEY(cid))';

 

Say i have a text input on the previous page named "tablename" why doesnt it still work? Please help.

Link to comment
https://forums.phpfreaks.com/topic/179194-creating-table-from-input/
Share on other sites

It still says...

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '".$tablename."( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id)

 

 

please help :confused:

Php variables only have meaning when used in php code. You would need to post your code for anyone here to be able to figure out why what you are doing does not work and to point out how you would need to do it.

 

It is generally a bad idea to let the user enter any table name used in a query or to specify the name of a table to be created because you must validate exactly what has been entered since you cannot use standard methods to protect against sql injection in variables that are use to hold table or column names.

i dont need it for just any user.. what I need this for my website.. when I create a new page, i want to place it into a category.. my categories are in different tables... there for i can select an existing table(category) or create a new category if i need it.. is there something simpler I can do? Im just not sure because im new to mysql. thanks  :D

You should not create new tables for each different category (i.e. the same type of data that you already have but just with a different value) because it makes it extremely inefficient to manage the information OR to simply search and find any information.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.