I'm having issues trying to name tables using php vars. I want to have tables containing user data for many different users (yes, I know about sessions, but this is for a lot of data). I would like to have the table name start with the username so that the program will know where each user's data is stored. I am currently trying the following code without good results:
Code: Select all
$sql="DROP TABLE IF EXISTS ".$_SESSION['username']."Table";
$result=mysql_query($sql, $conn);
$sql="CREATE TABLE ".$_SESSION['username']."Table (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(40), quantity INT)";
$result=mysql_query($sql,$conn);
For a user with username "bob", the table should be called "bobTable". However, I'm getting errors saying "error: mydatabase.table" does not exist. This tells me that the code isn't even recognizing the PHP variable at all and is just naming it "table". Is there an error in my syntax?