简体   繁体   English

无法从上一页(PHP和MYSQL)检索数据

[英]Data wasn't able to retrieve from the previous page (PHP and MYSQL)

I researched here in stackoverflow trying to find whether someone is also encountering the same problem. 我在这里进行了stackoverflow的研究,试图找出是否有人也遇到了相同的问题。 I know it's kind of easy and even I really don't know what's the error because there's no problem with my query. 我知道这很容易,甚至我真的不知道出了什么问题,因为查询没有问题。

On the previous page, here's my code to retrieve the ID Number so I'll be able to select the data with that ID number: 在前一页上,这是我的代码以检索ID号,因此我可以选择具有该ID号的数据:

<a href="package.php?place_id=<?php $row['place_id'];?>"><?php echo $row['place_name'];?></a>

I tried first to print the value of the place id and it works fine. 我首先尝试打印位置ID的值,但效果很好。 But when it was being called to the Package page, the data I want to show weren't displayed. 但是,当它被调用到Package页面时,我想要显示的数据没有显示。 I look at the URL and it shows this after the package.php 我看一下URL,它在package.php之后显示

place_id= place_id =

I don't know why it is blank, please check my code if there's missing or just wrong. 我不知道为什么它为空白,请检查我的代码是否丢失或错误。

In my package page, here's the PHP code: 在我的软件包页面中,这是PHP代码:

    <?php
        include("common/connect.php");
        $place_id = $_GET['place_id'];
        $result = mysql_query("SELECT * FROM package_items WHERE place_id = '$place_id'");
        $row1 = mysql_fetch_array(mysql_query("SELECT place_name FROM packages WHERE place_id = '$place_id'"));
        if($result === FALSE) {
        die(mysql_error()); // for better error handling
    }
?>

In HTML Code: 在HTML代码中:

<h1><?php echo $row1['place_name'];?></h1>
       <?php while($row=mysql_fetch_array($result)) {?>
       <?php echo $row['item_title'];?>
       <br>
        <a href="package-places.php"> Back </a>
        <?php } ?>

Please check my codes. 请检查我的代码。 Thanks. 谢谢。

You are not printing it. 您不打印它。

Change 更改

<?php $row['place_id'];?> // It will output nothing as no echo or print.

To

<?php echo $row['place_id'];?>

Rest of the code looks fine. 其余代码看起来不错。

Three suggestions: 1) $place_id = $_GET['place_id']; 三个建议:1)$ place_id = $ _GET ['place_id'];

Change to 改成

$place_id = ! $ place_id =! empty($_GET['place_id']) ? 空($ _GET ['place_id'])? $_GET['place_id'] : ''; $ _GET ['place_id']:''; // To avoid any warning. //避免任何警告。

2) Don't feed variable from $_GET or $_POST to any SQL. 2)不要将变量$_GET$_POST传递给任何SQL。

3) Don't use mysql_ functions as they are deprecated and will be remove in future versions of PHP. 3)不要使用mysql_函数,因为它们已被弃用,并将在以后的PHP版本中删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM