Jump to content

CREATE TABLE $var help


r00tk1LL

Recommended Posts

Here's a simple syntax question, how would I use a variable for a table name in this query?

$table = 'CREATE TABLE `$var` //How should I use this variable??
          ('
        . ' `id` INT(15) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
        . ' `pics` TEXT NOT NULL, '
        . ' `thumbs` TEXT NOT NULL'
        . ' )'
        . ' ENGINE = myisam;';

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/64447-create-table-var-help/
Share on other sites

Im trying it like this:

$table = "CREATE TABLE $var ('
        . ' `id` INT(15) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
        . ' `pics` TEXT NOT NULL, '
        . ' `thumbs` TEXT NOT NULL'
        . ' )'
        . ' ENGINE = myisam;";

and it doesn't seem to work??

Link to comment
https://forums.phpfreaks.com/topic/64447-create-table-var-help/#findComment-321330
Share on other sites

OK here's what I discovered if I run this with single quotes:

$table = 'CREATE TABLE `$uname` ('
        . ' `id` INT(15) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
        . ' `pics` TEXT NOT NULL, '
        . ' `thumbs` TEXT NOT NULL'
        . ' )'
        . ' ENGINE = myisam;';

It makes the table, but calls is $uname, the variables name instead of value.

 

If i run this with double quotes:

$table = "CREATE TABLE `$uname` ('
        . ' `id` INT(15) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
        . ' `pics` TEXT NOT NULL, '
        . ' `thumbs` TEXT NOT NULL'
        . ' )'
        . ' ENGINE = myisam;";

It finds the variables value, but fails to make the table!

 

PLEASE HELP

 

Link to comment
https://forums.phpfreaks.com/topic/64447-create-table-var-help/#findComment-321362
Share on other sites

$table = "CREATE TABLE `$uname` ('
        . ' `id` INT(15) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
        . ' `pics` TEXT NOT NULL, '
        . ' `thumbs` TEXT NOT NULL'
        . ' )'
        . ' ENGINE = myisam;";

$results = @mysql_query($table) or die(mysql_error());

I think this would work

Link to comment
https://forums.phpfreaks.com/topic/64447-create-table-var-help/#findComment-321371
Share on other sites

$table = "CREATE TABLE '$uname' (
       'id' INT(15) NOT NULL AUTO_INCREMENT PRIMARY KEY, 
       'pics' TEXT NOT NULL, 
       'thumbs' TEXT NOT NULL
       )'
       ENGINE = myisam;";

$results = @mysql_query($table) or die(mysql_error());

 

I think this may work better, I usually use phpmyadmin to create tables, but I know this option is not always available

Link to comment
https://forums.phpfreaks.com/topic/64447-create-table-var-help/#findComment-321379
Share on other sites

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.