隐藏字段如何删除url的最后一部分


hidden field how to remove last part of url?

我想从url中删除GET参数:

http://localhost/fadt/admin/edit_country.php?id=7

我希望我的url变成:

http://localhost/fadt/admin/edit_country

链接当前是这样生成的:

<button onClick="location.href='edit_country?id=<?php echo $row['COUNTRY_ID']; ?>'" class="btn btn-primary btn-xs" title="Edit"><i class="fa fa-pencil"></i></button>

使用带有POST方法的HTML表单代替按钮。

类似:

<form action="edit_country.php" method="post">
    <input type="hidden" value="<?php echo $row['COUNTRY_ID'];?>" name="id" />
    <input type="submit" class="btn btn-primary btn-xs fa fa-pencil" title="Edit"/>
</form>

代替

<button onClick="location.href='edit_country?id=<?php echo $row['COUNTRY_ID']; ?>'" class="btn btn-primary btn-xs" title="Edit"><i class="fa fa-pencil"></i></button>

然后在edit_country.php上用$_POST代替$_GET

这个id可以像您的按钮值一样容易地被操纵,所以请确保您正在验证执行用户是否有执行操作的权限。

更新,使用按钮:

<form method="post">
    <input type="hidden" value="<?php echo $row['COUNTRY_ID'];?>" name="id" />
    <button type="submit" class="btn btn-primary btn-xs" title="Edit"><i class="fa fa-pencil"></i></button>
</form>

不清楚这个问题,但我认为你需要这个

<?php
 $a =  explode('?','http://localhost/fadt/admin/edit_country.php?id=7');
echo rtrim($a[0], '.php')
 ?>