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

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

问题描述:

i am having a problem with the get method in php, i try to get a variable($profile_id) from one php page to another, the variable is working in this page

<?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>';
      }
     }
?>

but then in the followaction.php when i call the profid, It returns $profile_id(sting) instead of the number it should be representing

<?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);
}
?>

How can i fix this, everything is working but i cant transfer the profile_id to this page....

This does not work

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

If you do

echo $follow;

You will get something like this (Notice $profile_id has not been replaced)

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

You need to use double quotes if you want variable replacement

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