我查看了每个可能的论坛和问题页面,仍然无法理解为什么我的sql搜索没有返回任何值。它是用PHP脚本编写的,用于搜索用户在HTML页面上输入的名称并返回数据库中的所有列。
请注意,我对学习PHP和SQl相当陌生,所以请不要讨厌,如果这只是我愚蠢的哈哈。
提前致谢, 克里斯
<!DOCTYPE html>
<html>
<body>
<?php
$ServerName = "****";
$LogInUN = "*****";
$LogInPW = "******";
$DBName = "********";
$Connection = mysqli_connect($ServerName, $LogInUN, $LogInPW, $DBName);
if(!$Connection){
die("<p>Connection error!</p>" . mysqli_connect_error());
}
$Name = mysqli_real_escape_string($Connection, $_POST['Name']);
$Query = "SELECT Firstname FROM Students WHERE Firstname LIKE '%{%Name}%'";
$result = $Connection->query($Query);
echo $result;
echo $Name;
?>
</body>
</html>
答案 0 :(得分:1)
使用$ Name
$Query = "SELECT Firstname FROM Students WHERE Firstname LIKE '%{$Name}%'";
在$result = $Connection->query($Query);
行写下行
while($row = mysqli_fetch_assoc($result)) {
echo $row["Firstname"];
echo $Name;
}
删除$result = $Connection->query($Query);
并使用
$result = mysqli_query($Connection, $Query);
答案 1 :(得分:-1)
$ Query =&#34; SELECT Firstname FROM Students WHERE First&LIKE&#39;%{%Name}%&#39;&#34 ;; 用这个 $ Query =&#34; SELECT Firstname FROM Students WHERE LIKE LIKE&#39;%{$ Name}%&#39;&#34;;