I'm pretty new to php.. and this is probably a stupid mistake... but I have no idea what is going on. I'm trying to create a table in my database using php. I want to name the table after the username. I'm using the variable $tableusername
. Here's my code
$sql="SELECT * FROM userdata WHERE username='$username'";
$result=mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
{
$tableusername = $row["username"];
}
$create = "CREATE TABLE `".$tableusername."` ('
. ' `ID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, '
. ' `please` VARCHAR(50) NOT NULL, '
. ' `make` VARCHAR(50) NOT NULL, '
. ' `this` VARCHAR(50) NOT NULL, '
. ' `work` VARCHAR(50) NOT NULL'
. ' )'
. ' ENGINE = myisam;";
mysql_query($create)
?>
<html>
<head>
</head>
<body>
You have successfully signed up. <?php echo $tableusername ?>
</body>
</html>
So- This creates a table named $tableusername
. The variable doesn't carry over. BUT- when I echo $tableusername
- the variable carries over. I'm pretty new to this - so any help is appreciated.