Hey,

Im just wondering how i can get something like this to work:

$tablename = $_POST['tablename']; 
mysql_query(CREATE TABLE `databasename`.`$tablename` (`name` VARCHAR( 200 ) NOT NULL))

At the moment its coming up with an error because I am using a variable for the table name instead of inputting it normally.

Thanks,

Max

Mosh_1 commented: So do it like this: `$name` +0

you can do that.

try this:

$tablename = $_POST['tablename'];
$sql = "CREATE TABLE `databasename`.`{$tablename}` (//table fields here)";
mysql_query($sql);
$tablename = "test";
$query = "create table ".$tablename." (name varchar(200) not null )";
mysql_query($query);

Like this.

Thanks for the help :D however I don't see how this is not working :s

$sql = 'CREATE TABLE `web163-gallery-7`.`{$picurl}` (`name` VARCHAR( 200 ) NOT NULL ,`picurl` VARCHAR( 200 ) NOT NULL ,`group` VARCHAR( 200 ) NOT NULL ,`dateadded` TIMESTAMP( 200 ) NOT NULL DEFAULT CURRENT_TIMESTAMP ,`id` INT( 200 ) NOT NULL ,PRIMARY KEY ( `id` ) ,UNIQUE (`name` ,`picurl`)';

mysql_query($sql)

Missing ending )
P.S. group is a keyword. Its not advisable to use keywords as column names.
This works fine for me.

$sql = "CREATE TABLE test.".$picurl ."
(name VARCHAR(200) NOT NULL ,
picurl VARCHAR( 200 ) NOT NULL ,
group1 VARCHAR( 200 ) NOT NULL ,
dateadded TIMESTAMP( 200 ) NOT NULL DEFAULT CURRENT_TIMESTAMP ,
id INT( 200 ) NOT NULL ,
PRIMARY KEY ( id ) ,UNIQUE (name ,picurl))";
# Drop any existing table `posts`
# --------------------------------------------------------
DROP TABLE IF EXISTS `posts`;

# --------------------------------------------------------
# Table structure for table `posts`
# --------------------------------------------------------
CREATE TABLE posts (
                    post_id int(11) NOT NULL auto_increment,
					category_id int(11) NOT NULL,
					user_id int(11) NOT NULL,
					title varchar(150) NOT NULL,
					body text NOT NULL,
					posted timestamp,
					PRIMARY KEY (post_id)
					);

Hey,

Im just wondering how i can get something like this to work:

$tablename = $_POST['tablename']; 
mysql_query(CREATE TABLE `databasename`.`$tablename` (`name` VARCHAR( 200 ) NOT NULL))

At the moment its coming up with an error because I am using a variable for the table name instead of inputting it normally.

Thanks,

Max

Thanks ;) I thought it wasnt working but that was because i needed to call the table something with .jpg at the end and iv realised i cant do that. No worries iv found a work around.

Max

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.