Hello,
Please forgive me if this has been asked before, but I am trying to create a table from from a variable name that is concatenated and then passed. The issue is my table is never created.
<?PHP $Winning_Player1=$_POST['Winning_Player_1']; $Winning_Player2=$_POST['Winning_Player_2']; $Loosing_Player1=$_POST['Loosing_Player_2']; $Loosing_Player2=$_POST['Loosing_Player_2']; // this just makes it easy to modify the connection details site wide if details change $host ="localhost"; $user ="root"; $pwd =""; $db ="tennis_information"; $mysqli = mysqli_connect($host, $user, $pwd, $db); if (!$mysqli) { die('Could not connect: ' . mysql_error()); } //mysqli_select_db($db, $mysqli); $WinningPlayer1 = mysqli_query($mysqli, "select * from players where players.Player_Number = '$Winning_Player1'"); while ($row = $WinningPlayer1->fetch_assoc()) { $FirstNameWinningPlayer1 = $row["First_Name"]; $LastNameWinningPlayer1 = $row["Last_Name"]; } /* $WinningPlayer2 = mysqli_query($mysqli, "select * from players where players.Player_Number = '$Winning_Player1'"); while ($row = $WinningPlayer2->fetch_assoc()) { $FirstNameWinningPlayer2 = $row["First_Name"]; $LastNameWinningPlayer2 = $row["Last_Name"]; } $LoosingPlayer1 = mysqli_query($mysqli, "select * from players where players.Player_Number = '$Winning_Player1'"); while ($row = $LoosingPlayer1->fetch_assoc()) { $FirstNameLoosingPlayer1 = $row["First_Name"]; $LastNameLoosingPlayer1 = $row["Last_Name"]; } $LoosingPlayer2 = mysqli_query($mysqli, "select * from players where players.Player_Number = '$Winning_Player1'"); while ($row = $LoosingPlayer2->fetch_assoc()) { $FirstNameLoosingPlayer2 = $row["First_Name"]; $LastNameLoosingPlayer2 = $row["Last_Name"]; } */ // Concatenation Of String $combinedNamesWinningPlayer1 = $FirstNameWinningPlayer1."_".$LastNameWinningPlayer1; //This checks to see if the table exsist and if not will create the table $winningPlay1Name = "select * from ".$combinedNamesWinningPlayer1; $winPlay1Name = mysqli_query($mysqli, $winningPlay1Name); //if table is empty then create it if(empty($winPlay1Name)) { $sql = "CREATE TABLE " .$combinedNamesWinningPlayer1. "( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50), reg_date TIMESTAMP)"; echo "talbe Created"; } else { echo "created already"; } if (mysqli_query($winPlay1Name, $sql)) { echo "Table $combinedNames was created successfully"; } else { echo "Error creating table: " . mysqli_error($sql); } } else echo "The table for $FirstNameWinningPlayer1 $LastNameWinningPlayer1 already exsist"; ?>
EDITED By Benanamen - Added Code Tags