Zubrag.com
June 24, 2019, 03:21:48 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: need Help-trying to create a mysql table using a variable as the table name  (Read 8178 times)
n7qwl
Newbie
*
Posts: 2


« on: November 10, 2008, 01:54:19 AM »

I have an html form passing variable information to a php file that will create a mysql table (hopefully) using the value of one of the variables...   The html form has an input called (lastname).

In the php file I am trying to define the variable "$usertable" as $lastname and then... Create a table as follows:

$usertable = (`$lastname`);

$con = mysql_connect($hostname,$username,$password);
if (!$con)
  {
  die('Could not connect ' . mysql_error());
 }// Create table in $dbname database
mysql_select_db($dbname, $con) or die(mysql_error());


$sql = 'CREATE TABLE  `$usertable` ('
        . ' `ID` INT(6) NOT NULL AUTO_INCREMENT, '
        . ' `first` VARCHAR(20) NOT NULL, '
        . ' `middle` VARCHAR(15) NOT NULL, '
        . ' `last` VARCHAR(20) NOT NULL, '
 
and so on...   But the table it is creating is called "$usertable"  NOT the value of the input ("lastname").

Can anyone help me with this?

Logged
soul
Newbie
*
Posts: 2


« Reply #1 on: January 26, 2009, 06:53:58 PM »

try this

Code:
$usertable = (`.$lastname.`);

$con = mysql_connect($hostname,$username,$password);
if (!$con)
  {
  die('Could not connect ' . mysql_error());
 }// Create table in $dbname database
mysql_select_db($dbname, $con) or die(mysql_error());


$sql = 'CREATE TABLE  `$usertable` ('
        . ' `ID` INT(6) NOT NULL AUTO_INCREMENT, '
        . ' `first` VARCHAR(20) NOT NULL, '
        . ' `middle` VARCHAR(15) NOT NULL, '
        . ' `last` VARCHAR(20) NOT NULL, '

not sure if that will work if not wait for some one else to reply.
Logged
pipisdicelana
Newbie
*
Posts: 6


« Reply #2 on: February 05, 2009, 07:17:47 AM »

Use double quoted please..  Roll Eyes
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC