[英]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.