PHP查询无法通过HTML href链接工作

时间:2016-06-03 15:35:14

标签: php html sql

创建一个允许我按县搜索位置的网页。我试图在我的基本主页上创建一个href链接,它将调用Php函数,然后显示我的Sql数据库的结果。 不知道为什么,但是当我点击href链接时,主页只是空白,没有返回任何值。已经过代码和数据库,已经向几个朋友展示并且无法弄清楚是什么问题。任何帮助表示赞赏!

这是我的index.php主要主页代码(href大约有一半)

<!DOCTYPE HTML>

<?php
include("includes/db.php");
include("getAntrim.php");
include("functions/functions.php");
?>


<html>

<head>

<link rel = "stylesheet" href="styles/styles.css" media = "all"/>

<title>Location Scout</title>

</head>

<body>

<!-- Main container starts -->

<div class ="main_wrapper">

<div id="form">
<form method="get" action="results.php" enctype="multipart/form-data">

<input type="text" name="user_query" placeholder="Search for location"?>
<input type="submit" name="search" value="search"/>

</form>
</div>

<div class ="content_wrapper">
<div id ="left_sidebar">
<div id="sidebar_title">Search by County</div>

<a href="getAntrim.php">Antrim</a><br></br>


<div id ="content_area">
<div id ="products_box">

<!-- THIS IS WHERE FETCHED DATABASE INFO WILL GO -->


<?php
getAntrim();

?>


</div>
</div>
</div>

<!-- Main container ENDS -->

</div>

</div>

</body>

</html>

这是我的getAntrim.php函数,它应该通过sql数据库排序然后返回指定的值。

<?php

    include ("includes/db.php");

    if (isset ($_GET['getAntrim'])) {

        $get_loc_co = "select * from locations where county='Antrim'";
        $run_loc_co = mysqli_query($db, $get_loc_co); //Gets data from db and presents on main  page

        $count = mysqli_num_rows($run_loc_co);

        if ($count==0) {

            echo "<h2>No locations found in this category.";

        }//if

        while ($row_loc_co=mysqli_fetch_array($run_loc_co)) {

                //variable to store values
                $loc_id = $row_locations['loc_id'];
                $loc_name = $row_locations['loc_name'];
                $town = $row_locations['town'];
                $county = $row_locations['county'];
                $productions = $row_locations['productions'];
                $disabled = $row_locations['dis_access'];
                $parking = $row_locations['parking'];
                $visitor = $row_locations['vis_facs'];
                $transport = $row_locations['public_trans'];
                $cost = $row_locations['cost'];
                $accom = $row_locations['accom'];
                $latitude = $row_locations['latitude'];
                $longitude = $row_locations['longitude'];
                $description = $row_locations['loc_desc'];
                $keyword = $row_locations['loc_keyword'];
                $loc_image = $row_locations['loc_img'];


                echo "
                <div id= 'single_location'>
                <h3>$loc_name</h3>
                <img src = 'Admin_area/location_images/$loc_image' width='180' height = '180'/><br>
                <p><b>Productions: $productions </b></p>
                <p><b>Description: $description </b></p>

                </div>
                ";

        }//while
    }//if


?>

是第一次发布海报,所以希望发布这个好!任何建议表示赞赏。

2 个答案:

答案 0 :(得分:1)

你正在检查一个你没有传入的查询参数:

<a href="getAntrim.php">Antrim</a><br></br>

    if (isset ($_GET['getAntrim'])) {
                      ^^^^^^^^^

$_GET包含网址查询参数,例如example.com?foo=bar(foo = bar部分)。由于href中没有查询参数,isset()正确返回false,因此忽略整个数据库代码部分。

你可能想要

<a href="getAntrim.php?getAntrim">Antrim</a><br></br>
                      ^^^^^^^^^^

让这项工作原样。

答案 1 :(得分:0)

感谢您回复我们。我已经尝试过这些东西,它现在点击了另一个页面,但出现以下错误。将为ref:

粘贴错误消息和Php代码

Error message

php code