PHP $ _GET方法不起作用/遵循系统

时间:2014-09-07 20:11:48

标签: php mysql session mysqli

我在php中遇到get方法的问题,我尝试从一个php页面到另一个php页面获取一个变量($ profile_id),该变量在这个页面中工作

<?php
    $follow="";
    $loggedinid=$_SESSION['userid'];
    $sqll = "SELECT id FROM Follow WHERE user_one='$loggedinid' AND user_two='$profile_id'"; 
  if($profile_id != $_SESSION["userid"]){
     $check= mysqli_query($db_conx, $sqll);
      if(mysqli_num_rows($check) == 1){
        $follow='<a href="followaction.php?followaction=unfollow&profid=$profile_id">Unfollow</a>';//This is where i try to put the variable, so i can call it with the get method on followaction.php
      }else{
        $follow='<a href="followaction.php?followaction=follow&profid=$profile_id">Follow</a>';
      }
     }
?>

然后在followaction.php中,当我调用profid时,它返回$ profile_id(sting)而不是它应该代表的数字

<?php

include_once("php_includes/check_login_status.php");

$followaction=$_GET['followaction'];

$profileid = $_GET['profid'];

$loggedinid = $_SESSION['userid'];

$loggedinusername = $_SESSION['username'];

 if($followaction == 'follow'){
    mysqli_query($db_conx, "INSERT INTO Follow VALUES('','$loggedinid','$profileid')");
}

if($followaction == 'unfollow'){
    $sql = "DELETE FROM Follow WHERE user_one='$loggedinid' AND user_two='$profileid'";
    mysqli_query($db_conx, $sql);
}
?>

我如何解决这个问题,一切正常,但我无法将profile_id传输到此页面....

1 个答案:

答案 0 :(得分:0)

这不起作用

 $follow='<a href="followaction.php?followaction=unfollow&profid=$profile_id">Unfollow</a>';

如果你这样做

echo $follow;

你会得到这样的东西(注意$ profile_id没有被替换)

 <a href="followaction.php?followaction=unfollow&profid=$profile_id">Unfollow</a>

如果您想要变量替换

,则需要使用双引号
 $follow="<a href=\"followaction.php?followaction=unfollow&profid=$profile_id\">Unfollow</a>";