我试图显示“area”和“block_number”中的所有平台,它们在URL中传递到我的页面。但是,当我运行URL中包含“area”和“block_number”的页面时,我没有得到任何行。我只得到了else语句“对不起,没有结果”。有人能告诉我哪里做错了吗?
<?
//// Get items from url
$area1 = $_GET[area];
$block_number1 = $_GET[block_number];
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = 'SELECT * from platform_locations where area = $area1 and block_number = $block_number1';
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc())
{
echo '<div class="col-lg-4 col-md-4 col-sm-6 wow bounceInUp" data-wow-duration="1s" data-wow-delay="0.4s">
<div class="feature-1 box-shadow">
<img src="img/platform_icon.png" alt="">
<h3 class="feature__title">'. $row['area'] .' '. $row['block_number'] .'</h3>
<p class="feature__text">
Structure Name: '. $row['structure_name'] .'<br>
Attended: '. $row['attended'] .'<br>
<a href="Structure_info.php?p_id='. $row['p_id'] .'" target="_self" class="btn btn-sm btn-red">More Information</a>
<br>
<font color="Tomato">'. $row['remove_date'] .'</p>
</div></div>';
}
}
else{
echo '<br>Sorry No Results';
}
?>
1条答案
按热度按时间6ljaweal1#
等号和$area1之间有一个空格,这使得它返回0行。我相信其他注解也是正确的,我将按照@Barmar的建议研究如何使我的代码更安全。
area = $area1
我更改了area =$area1
,它开始按预期工作。