我有一个PHP文件,用于链接到我设置的测试SQL表。问题是在我的搜索框中输入数据并没有得到我想要的结果。
首先,PHP代码:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT ID, FirstName, LastName FROM 'create'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result)>0) {
// output data of each row
while($row=mysqli_fetch_assoc($result)) {
echo "ID: " . $row["ID"]. " - Name: " . $row["FirstName"]. " " . $row["LastName"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
从CSV版本复制并粘贴的SQL文件,按ID,FirstName,LastName的顺序...
1,"Ryan","Butler"
2,"Ryan","Butler"
3,"Brent","Callahan"
4,"Harry","Callahan","makemyday@dirtyharry.net"
5,"Luke","Cage","luke@mywifeisdead.com",
6,"Jessica","Jones","jessica@getkilgrave.org",
在我的搜索框中输入上述任何单词的结果应该会给我6. Jessica的结果。琼斯。 (我不打算搜索电子邮件,我不知道为什么要包含它们。)相反,无论我输入什么,我都会得到“0结果”。
可能只有一件事我错了,但如果我知道它是什么我会被诅咒。再说一次,PHP不是我的强项。
答案 0 :(得分:3)
您的表名应该是反引号,而不是引号。
$sql = "SELECT ID, FirstName, LastName FROM `create`";