php 脚本未正确传递值或未从 mysql 正确查询

php script isn't passing value correctly or isn't querying from mysql correctly

我有两个 php 脚本 - 一个是主页 (index.php) 另一个 (refresh.php) 从 mysql table 获取信息并显示它。

index.php 中建立与 mysql 数据库的连接后,我查询以获得 id传递给 refresh.php

<?php 
  $stagequery = "SELECT stage FROM teams WHERE team_name = '$team_name'";
  $stageresult = mysql_query($stagequery) or die('Error, couldnt find a clue to   display'.mysql_error()); 
  $stagerow = mysql_fetch_assoc($stageresult);
  $id = $stagerow['stage'];
?>
<iframe method="get" id="dynamic-content" src="refresh.php?id=$id"  />

然后在 refresh.php 中,我使用 id 执行以下操作:

<html>
<meta http-equiv="refresh" content="5">
<body>
<?php
if (isset($_GET['id']))
{
    $id = $_GET['id'];  
    echo $_GET['id'];
    //*Connect to database here*
    $query = "SELECT clue FROM clues WHERE id='$id'";
    $result = mysql_query($query) or die('Error find a clue to table'.mysql_error()); 
    $row = mysql_fetch_assoc($result);
    echo $row['clue'];
    echo "test";
}
?>
</body>
</html>

所有这些都应该显示的框显示 $id(来自 echo $_GET['id']),它也显示测试。我不明白 id 的值为什么没有传递到脚本中(我尝试在 index.php[= 中硬编码 $id 的值43=],但这也不起作用)。

这就是罪魁祸首。

<iframe method="get" id="dynamic-content" src="refresh.php?id=$id"  />

您应该使用 php 来回应 html 中的 $id

<iframe method="get" id="dynamic-content" src="refresh.php?id=<?php echo $id; ?>"  />

否则你只是post变成了$id而不是$id

的值