在阅读了一个又一个指南后,我花了很长时间试图弄清楚这一点,但我无法理解。我有 3 个文件 - user.php、map.php 和 newaddress.php。我只包含了我认为对这个问题重要的部分。如果需要,很乐意提供更多信息。
user.php 将“mapnumber”传递给map.php。
用户.php
<form action="map.php" method="post">
<input type="hidden" name="mapnumber" value="'. $row["mapnumber"].'"/>
<input type="hidden" name="process" value="process"/>
<button class="btn btn-primary" type="submit" name="getmap">Process</button>
</form>
map.php 接收“mapnumber”并从数据库中生成具有匹配“mapnumber”的地址列表。从map.php,用户可以添加新地址,该地址采用“mapnumber”值并在newaddress.php中进行处理。
map .php
$mapnumber = $mysqli->escape_string($_POST['mapnumber']);
<form action="newaddress.php" method="post">
<input class="" id="mapnumber" name="mapnumber" value="<?php echo $mapnumber ?>">
<button class="btn btn-primary" id="addaddress" type="submit">Add Address</button>
</form>
newaddress.php 使用“mapnumber”值将地址添加到数据库,然后重定向回map.php,其中它应该根据“mapnumber”生成地址列表,但map.php 不会获取“mapnumber” "来自 newaddress.php,因此不会生成地址列表。
新地址.php
$mapnumber = $mysqli->escape_string($_POST['mapnumber']);
header("Location: map.php");
exit;
请帮忙
最佳答案
您可以像这样设置 get 变量:
$mapnumber = $mysqli->escape_string($_POST['mapnumber']);
header("Location: map.php?nr=". $mapnumber);
exit;
比map.php
中的你可以通过以下方式得到它:
$mapnumber = $mysqli->escape_string($_GET['nr']);
关于php - header() 重定向后如何使用变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50489726/