为什么我的过滤器页面未在数据库中查找结果?

时间:2017-04-10 14:47:27

标签: php html sql search filter

我正在创建一个过滤页面,该页面应该返回一个结果表,该结果表取决于从下拉列表中选择的选择。 我为此生成了代码,没有发现错误。但是,尽管它们存在于数据库中,但没有结果显示出来。

我错过了什么吗? 如果需要任何进一步的信息,请告诉我。

任何帮助将不胜感激!

    <?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>

1 个答案:

答案 0 :(得分:0)

尝试这个,如果它仍然没有显示任何检查变量用于调用另一个的

<?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

未创建