Php 使用post方法将变量的值传递到下一页

Php 使用post方法将变量的值传递到下一页,php,post,Php,Post,在下面的代码中,我想使用post方法将变量$user\u id传递到下一页,假设我的下一页是followers.php。整个代码就是link本身,我想把post方法放在其中,这样在单击链接时,变量也被传递到follower.php。不想使用会话 <a href='follower.php' style='text-decoration:none;'> <h2>Followers</h2> <?php $checkfollowers = "SELECT *

在下面的代码中,我想使用post方法将变量
$user\u id
传递到下一页,假设我的下一页是
followers.php
。整个代码就是link本身,我想把post方法放在其中,这样在单击链接时,变量也被传递到
follower.php
。不想使用会话

<a href='follower.php' style='text-decoration:none;'>
<h2>Followers</h2>
<?php
$checkfollowers = "SELECT * FROM follow_user WHERE user_id='$user_id'";
$resultfollowers = mysqli_query($con,$checkfollowers);
echo mysqli_num_rows($resultfollowers );
?></a>

我想post方法的代码是正确的:

 <form method="get" action="follower.php">
 <input type="hidden" name="varname" value="user_id">
 <input type="submit">
 </form>   


因此,如何将此post方法放入其他代码中,因此单击,
follower.php
打开,变量也传递到此页面。

您使用的是GET方法。换成

<form method="POST" action="follower.php">
 <input type="hidden" name="user_id" value="user_id">
 <input type="submit">
 </form>

同时将隐藏字段的名称更改为user_id。现收为

<?php

$user_id = $_POST['user_id'];
$checkfollowers = "SELECT * FROM follow_user WHERE user_id='$user_id'";
$resultfollowers = mysqli_query($con,$checkfollowers);
echo mysqli_num_rows($resultfollowers );
?>

您谈论的是post方法,但在代码中您使用的是GET方法。您可能想考虑将此更改为POST。这样,表单中填写的内容就不会进入URL。(更安全一点)。在此之后,您可以调用全局变量$\u POST['user\u id']

链接无法发布数据,只能获取

使用:


$user\u id=$\u POST['user\u id']也可以从SQL注入中考虑一些保护项,在您的情况下最简单的方法是$UersIdI=(int)$POST([用户erID)];表单的方法应该是
post
而不是
get
。然后对于隐藏字段,使用
@Epodax,OP使用post方法编写了
我的错误,好像我解释了他的问题/文本:)你是对的链接不使用post,而是通过get方法发送变量,你能告诉
follower.php吗?user_id=1
这里我将发送什么而不是1,$user\u id?要获取$user\u id,请使用$\u会话或从post表单获取。
<a href='follower.php?user_id=1' style='text-decoration:none;'>
$user_id = $_GET['user_id'];