Php Mysql Problem

Discussion in 'Gaming' started by willwill100, Feb 19, 2006.

  1. willwill100

    willwill100 Well-Known Member

    Age:
    32
    Posts:
    231
    Likes Received:
    0
    Joined:
    Nov 6, 2005
    Location:
    Manchester, UK
    Okay im working with a mysql database here. In my php file i have this code with the $compname having some text value that has been posted from another page:

    Code:
    $sql = 'CREATE TABLE `$compname` ('
            . ' `Name` VARCHAR(25) NOT NULL, '
            . ' `Sail Number` VARCHAR(7) NOT NULL, '
            . ' `Class` VARCHAR(20) NOT NULL, '
            . ' `Position` VARCHAR(3) NOT NULL'
            . ' )'
            . ' TYPE = myisam';
    
    it just creates a table with the name "$compname" and i want it to have the name of what is assigned to "$compname". Any ideas? Thanx

    Will
     
  2. willwill100

    willwill100 Well-Known Member

    Age:
    32
    Posts:
    231
    Likes Received:
    0
    Joined:
    Nov 6, 2005
    Location:
    Manchester, UK
    cum on guys! i really need a hand!
     
  3. SwAT

    SwAT Well-Known Member

    Posts:
    2,689
    Likes Received:
    0
    Joined:
    May 9, 2005
    Location:
    Connecticut, USA
    Put the value in doule quotes - " " not ' '. Anything in double quotes is evaluted so your varialbe $copname will come out to be the name of the table. Using single quotes treats it literally so you're just using $copname instead of evaluating the variable. Solution:

    Code:
    $sql = "CREATE TABLE `$compname` (
           `Name` VARCHAR(25) NOT NULL, 
           `Sail Number` VARCHAR(7) NOT NULL, 
           `Class` VARCHAR(20) NOT NULL, 
           `Position` VARCHAR(3) NOT NULL
           ) TYPE = myisam";
     

Share This Page