PHP-数据未传输到下一页

PHP-数据未传输到下一页,php,mysql,Php,Mysql,我有下面的代码,当它转到下一个PHP页面'individual\u item\u page.PHP' 注意:我已经为SQL查询硬编码了经度和纬度 <table class="center"> <!-- SEARCH BY LOCATION --> <?php $LOCATION = $_POST['location']; $result = $conn->prepare("SELECT dog_park_na

我有下面的代码,当它转到下一个PHP页面'individual\u item\u page.PHP'

注意:我已经为SQL查询硬编码了经度和纬度

<table class="center">          
    <!-- SEARCH BY LOCATION -->
    <?php
    $LOCATION = $_POST['location'];
    $result = $conn->prepare("SELECT dog_park_name,3956*2*ASIN(SQRT(POWER(SIN((-27.318672099999997 - latitude)*pi()/180/2),2)+COS(19.286558 * pi()/180)
    *COS(latitude * pi()/180)*POWER(SIN((152.8500067 -longitude)* pi()/180/2),2)))
    as distance FROM dog_parks.items having distance < $LOCATION ORDER BY distance;");
    $result->execute();
    for($i=0; $row = $result->fetch(); ){ 
        $_SESSION["LOCATION".$i] = $row[0]; 
        ?>
        <tr><!-- Adding the first table row -->
            <th>Dog Park</th><!-- Adding the  table header -->
        </tr>
        <tr><!-- Adding the second table row -->
            <td>
                <a href="individual_item_page.php?location='<?php $row[$i] ?>' " >
                    <?php echo $row[$i] ?>
                </a>
            </td>   
        </tr>                       
    <?php } ?>
</table>   

狗公园
下面是执行脚本时URL中的结果。 仅显示

我认为这是因为SQL查询中选择了多个项目,例如:dog\u park\u name、经度和纬度。
我只需要狗公园的名字被跟随到下一页


有什么想法吗?

从代码中我缺少了一个
会话\u start()
,除了您的for缺少
I++

我认为您应该使用以下内容:

echo "<table>";
while($row = $result->fetch()) 
{
    $_SESSION["LOCATION".$i] = $row[0]; 
    echo "<tr>". //Adding the first table row
    "<th>Dog Park</th>". //Adding the  table header
    "</tr><tr>". //Adding the second table row
    "<td><a href='individual_item_page.php?location=". $row[$i] ."'>".
    // line above will give you URL Problems in my opinion
    // since you are adding not replaceing
    $row[$i] ."</a></td>".
    "</tr>".   
}
echo "</table>";
echo”“;
而($row=$result->fetch())
{
$\会话[“位置”。$i]=行[0];
echo”“//添加第一个表行
“Dog Park”。//添加表格标题
“”.//添加第二个表行
"".
"".   
}
回声“;
老实说,为什么不把它粘贴到URL中呢?
不像您使用正则表达式清理URL。

从代码中我缺少一个
会话\u start()
,而您的for缺少
I++

我认为您应该使用以下内容:

echo "<table>";
while($row = $result->fetch()) 
{
    $_SESSION["LOCATION".$i] = $row[0]; 
    echo "<tr>". //Adding the first table row
    "<th>Dog Park</th>". //Adding the  table header
    "</tr><tr>". //Adding the second table row
    "<td><a href='individual_item_page.php?location=". $row[$i] ."'>".
    // line above will give you URL Problems in my opinion
    // since you are adding not replaceing
    $row[$i] ."</a></td>".
    "</tr>".   
}
echo "</table>";
echo”“;
而($row=$result->fetch())
{
$\会话[“位置”。$i]=行[0];
echo”“//添加第一个表行
“Dog Park”。//添加表格标题
“”.//添加第二个表行
"".
"".   
}
回声“;
老实说,为什么不把它粘贴到URL中呢?
不像您使用regex清理URL。

问题是您没有回显
$row[$i]

更改:

<a href="individual_item_page.php?location='<?php $row[$i] ?>' " >

问题是您没有回显您的
$行[$i]

更改:

<a href="individual_item_page.php?location='<?php $row[$i] ?>' " >

您将url从一个页面传递到另一个页面时出错。这就是它不重定向的原因

<a href="individual_item_page.php?location='<?php echo $row[$i]; ?>' " >

您将url从一个页面传递到另一个页面时出错。这就是它不重定向的原因

<a href="individual_item_page.php?location='<?php echo $row[$i]; ?>' " >

这就是为什么当您不检查错误或启动会话时,您不会得到任何结果。循环中缺少增量计数器如果您的PDO对象(假设这是PDO,而不是mysqli)未配置为引发异常,它将自动出错。在任何查询之前,
$conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION)
因此查询本身将抛出错误。您需要为
$LOCATION
使用占位符和
bindParam()
,而不是在查询中放置$\u POST值,因为
$LOCATION
的任何非数字值都会破坏您的查询(易受SQL注入攻击)。循环的语法似乎不完整。在关闭循环之前,在循环的最后一个添加$i++;。无法增加计数器变量,导致$i设置为0;是否包含会话_start();在这两个页面的顶部,因为我没有在代码中看到这些内容,这就是为什么当您不检查错误或启动会话时,您不会得到任何结果。如果您的PDO对象(假设这是PDO,而不是mysqli),则循环中缺少增量计数器未配置为引发异常,它将以静默方式出错。在任何查询之前,
$conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
因此查询本身将引发错误。您需要使用占位符和
bindParam()
$LOCATION
,而不是在查询中放置$\u POST值,因为
$LOCATION
的任何非数字值都会中断查询(易受SQL注入攻击)。循环的语法似乎不完整。在关闭循环之前,在循环的最后一个添加$i++;。您无法增加计数器变量,这导致$i设置为0;您是否在两个页面的顶部都包含session_start();因为我在您的代码中没有看到它们谢谢,我错过了。谢谢,我错过了。