eugene2009 Posted October 27, 2009 Share Posted October 27, 2009 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. Quote Link to comment Share on other sites More sharing options...
gevensen Posted October 27, 2009 Share Posted October 27, 2009 you cant put the variable into the table name itself try CREATE TABLE ".$tablename." Quote Link to comment Share on other sites More sharing options...
eugene2009 Posted October 27, 2009 Author Share Posted October 27, 2009 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 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 27, 2009 Share Posted October 27, 2009 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. Quote Link to comment Share on other sites More sharing options...
eugene2009 Posted October 27, 2009 Author Share Posted October 27, 2009 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 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 27, 2009 Share Posted October 27, 2009 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. 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.