这是我的代码
<?php
$servername = "localhost:3307";
$username = "root";
$password = "";
$dbname = "female"; //database
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname); //open ng connection
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$username = $_POST['username'];
$sql = "SELECT * FROM $username";
$result = $conn->query($sql);
echo "<div class='con'>";
echo "Men";
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<table id='contestant'>";
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[6]."</td>";
echo "</tr>";
echo "</table>";
echo "</div>";
}
} else
{
echo "<div class='con'>";
echo "<ul id='contestant'>0 Contestant</ul>";
echo "</div>";
}
?>
$ _POST [&#39;用户名&#39;]是用户输入用户名的输入名称,因为它用作表名。还要确定应显示哪个表。我的问题是我的代码无法正常工作,这就是为什么我可以在不知道表名的情况下显示表格。