Php 为什么我的筛选页面在数据库中找不到结果?
我正在创建一个过滤器页面,该页面将根据从下拉列表中选择的内容返回一个结果表。 我已经为此生成了代码,没有发现任何错误。但是,尽管数据库中存在结果,但没有显示结果 我错过什么了吗? 如果需要更多信息,请告诉我 任何帮助都将不胜感激Php 为什么我的筛选页面在数据库中找不到结果?,php,html,sql,search,filter,Php,Html,Sql,Search,Filter,我正在创建一个过滤器页面,该页面将根据从下拉列表中选择的内容返回一个结果表。 我已经为此生成了代码,没有发现任何错误。但是,尽管数据库中存在结果,但没有显示结果 我错过什么了吗? 如果需要更多信息,请告诉我 任何帮助都将不胜感激 <?php error_reporting(E_ALL); ini_set('display_errors','1'); $search_output= ""; $link= mysqli_connect("localhost","root","")
<?php
error_reporting(E_ALL);
ini_set('display_errors','1');
$search_output= "";
$link= mysqli_connect("localhost","root","");
mysqli_select_db($link,"assessment_centre_app");
if(isset($_POST['submit'])) {
$Name_FK = $_POST['Name_FK'];
$sqlCommand = mysqli_query($link, "SELECT *
FROM scores
WHERE 'Name_FK' = {'$Name_FK'}");
$query = mysql_query($sqlCommand) or die (mysql_error());
$count = mysqli_num_rows($query);
if($count > 1) {
$search_output .="$count results for $searchquery";
while($row = mysql_fetch_array($query)) {
$Candidate_Name_FK = $row["Candidate_Name_FK"];
$search_output .="Item ID: $Candidate_Name_FK <br />";
}
} else {
$search_output= "0 results found";
}
}
?>
<html>
<head>
</head>
<body>
<form action="http://localhost/scoresheet/scoresheetfilter.php" method="POST">
<label> Assessment Day Name </label>
<select name = "Name_FK">
<?php
$res=mysqli_query($link,"SELECT * FROM scores");
while($row=mysqli_fetch_array($res))
{
?>
<option>
<?php echo $row["Name_FK"]; ?>
</option>
<?php } ?>
</select>
<br>
<input name ="myBtn" id="submit" type="submit" >
<br>
</form>
<div>
<?php echo $search_output;
?>
</div>
</body>
</html>
如果仍然没有显示任何内容,请尝试此操作,检查用于调用另一个变量的变量
<?php
error_reporting(E_ALL);
ini_set('display_errors','1');
$search_output= "";
$link= new mysqli("localhost", "user_name", "password", "database");
if(isset($_POST['submit'])) {
$Name_FK = $_POST['Name_FK'];
$sqlCommand = "SELECT * FROM scores WHERE Name_FK='$Name_FK'";
$query = mysqli_query($linnk, $sqlCommand) or die (mysqli_error());
$count = mysqli_num_rows($query);
if($count > 1) {
$search_output .="$count results for $searchquery";
while($row = mysqli_fetch_array($query)) {
$Candidate_Name_FK = $row["Candidate_Name_FK"];
$search_output .="Item ID: $Candidate_Name_FK <br />";
echo $search_output; //echo to check result
}
} else {
$search_output= "0 results found";
echo $search_output; //echo to check result
}
}
?>
现在编辑
变数
$searchquery
未创建您可以尝试将{}的外部放置吗{$Name_-FK}“Name_-FK”应该是反勾,而不是引号,或者什么都没有。引号用于字符串。你也乐于接受SQL注入。嗨,刘易斯,谢谢你的建议。我试过了,但我仍然有同样的问题。嗨,克里斯,我也没有用回勾的运气。这只是一个概念证明,安全性将包含在完整版本中。使用:$sqlCommand=mysqli_query$link更新此行,从Name_FK='$Name_FK'的分数中选择*;嗨,JBoy,不幸没有运气。您还可以提供其他建议吗?但您确定您已将表单发布到此页面,因为它使用POST。您不确定这是什么意思?你能解释一下吗?我已经编辑了上面的代码,没有错误。但请确保表单已提交到此页面,否则它将无法工作。如果您仍然对代码有任何疑问,请删除ifisset['submit']{,以查看脚本是否显示任何错误。