[英]php/hmtl header() not redirecting to page with id in url
情况:我有一个成员数据库概述,用户可以在其中单击表中的“更新成员”链接,该链接重定向到显示单击成员数据的页面。 在 url 中,它获取参数 Lid.php?lidnummer=4(任何其他 id)。
在该页面上有一个表单,允许用户在按下提交按钮后通过 create.php 文件向该成员添加电话号码。 这个页面应该重定向回会员页面lid.php?lidnummer=4 并添加了新的电话号码。
我正在通过隐藏表单字段传递lidnummer,并尝试在header() 函数中使用它。
header("location: ../lid.php?lidnummer=' . $lidnummer . '");
只有在重定向后 url 显示:lid.php?lidnummer=%27%20.%205%20.%20%27 并且我在页面上收到“调用成员函数”错误,因为页面显示成员在按下“更新成员”按钮后,通过 $_GET 获取lidnummer 作为参数的函数获取数据。
<?php
if(isset($_GET['lidnummer']))
{
include 'includes/read.php';
$lidnummer = $_GET['lidnummer'];
?>
<div class="contact-form">
<h3>Voeg contactgegevens toe:</h3>
<form action="includes/create.php" method="POST"><b>
<label for="telefoonnummer">
Telefoonnummer:
<input type="text" name="telefoonnummer">
</label>
<input type='hidden' name='lidnummer' value='<?php echo $lidnummer ?>'>
<button type="submit" name='add_telnr'>Voeg telnr toe</button>
</form><br>
<form action="includes/create.php" method="POST">
<label for="email">
Email:
<input type="text" name="email">
</label>
<button type="submit" name='add_email'>Voeg email toe</button></b>
</form><br>
</div>
<div>
<h3>Lid:</h3>
<table>
<tbody>
<tr>
<td>#</td>
<td>Info</td>
<td>Pas aan</td>
<td>Delete</td>
</tr>
<?php show_single_lid($conn, $lidnummer); ?>
</tbody>
</table>
</div>
<?php } ?>
所以我有两个问题:
header("Location: ../lid.php?lidnummer=$lidnummer");
使用双引号 ( "
),您不需要将字符串与点符号连接起来。
你得到的奇怪 URL 是在它周围放置了不必要的单引号、点和空格的结果。 如果你仔细看:
%27%20.%205%20.%20%27
URL 中不能正常写入的字符被编码为:%xx,其中 xx 是一个数字。 所以:
%27 = '
%20 = 空格
这意味着,奇怪的字符串解析为' . 5 . '
' . 5 . '
' . 5 . '
这正是您放在双引号中的内容: ' . $lidnummer . '
' . $lidnummer . '
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.