I’m trying to create a SQL table in PHP using the following code:
$sql = "CREATE TABLE `$DBName`.`$login`_clients (
ClientID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`ClientID`),
AgentClients varchar(15),
ClientTotal int
)";
The botton script runs fine and saves the database as my $login query. I wanted to save the table as $login_clients however. Ex. $login="Fred", then the table would be named Fred_clients. I have tried a few different methods of combining variables with text but can’t get the format down. Any suggestions?
$sql = "CREATE TABLE `$DBName`.`$login`_clients (
ClientID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`ClientID`),
AgentClients varchar(15),
ClientTotal int
)";
You just have your back tick in the wrong place, it should go after
_clients. The problem you likely ran into was that the PHP interpreter then thought your variable was called$login_clientsinstead of$login, which can be solved by wrapping the variable in curly braces{}.