Login    Forum    Search    FAQ   Blog

Board index » Server Side Development » PHP




 Page 1 of 1 [ 7 posts ] 



Author Message
 Post subject: Creatin a Table 4m input
 Post Posted: Thu Nov 12, 2009 11:16 am 
Offline

Joined: Sat Feb 21, 2009 2:25 pm
Posts: 51
I m havin an issue .. how could !!! i create a table in a mysql
db 4m a users input?

Code:
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 m havin a text input on da prev page namd "tablename" why doesnt it
still work? Pls do help.


Top 
 Post subject: Re: Creatin a Table 4m input
 Post Posted: Thu Nov 12, 2009 11:16 am 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
you cant keep da var in 2 da table name itself

try
Code:

CREATE TABLE ".$tablename."



Top 
 Post subject: Re: Creatin a Table 4m input
 Post Posted: Thu Nov 12, 2009 11:17 am 
Offline

Joined: Sat Feb 21, 2009 2:25 pm
Posts: 51
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:


Top 
 Post subject: Re: Creatin a Table 4m input
 Post Posted: Thu Nov 12, 2009 11:18 am 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
Php vars only have a 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.


Top 
 Post subject: Re: Creatin a Table 4m input
 Post Posted: Thu Nov 12, 2009 11:18 am 
Offline

Joined: Sat Feb 21, 2009 2:25 pm
Posts: 51
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


Top 
 Post subject: Re: Creatin a Table 4m input
 Post Posted: Thu Nov 12, 2009 11:18 am 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
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.


Top 
 Post subject: Re: Creatin a Table 4m input
 Post Posted: Thu Nov 12, 2009 11:18 am 
Offline

Joined: Sat Feb 21, 2009 2:25 pm
Posts: 51
kk thanks :-)


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 7 posts ] 




Board index » Server Side Development » PHP


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron