<?php
$current_subject = $_GET['subject_id'];
$current_content = $_GET['note_id'];
echo "<form method=\"post\" action=mainpage.php?subject_id=".$current_subject."¬e_id=".$current_content.">";
?>
<input type='text' name='list_item' value=''>
<input type='submit' name="new_item" value="New Item">
</form>
问题是,当 GET
变量之一是两个单词时,链接不会那样写。例如,如果 $current_subject="Advanced Chemistry"
和 $current_content="Valence Electrons"
链接将显示为:
<form method="post" action="mainpage.php?subject_id=Advanced" chemistry¬e_id="Valence" electrons>
最佳答案
您需要urlencode()
像这样的变量:
<?php
$current_subject = $_GET['subject_id'];
$current_content = $_GET['note_id'];
$subject = urlencode($current_subject);
$content = urlencode($current_content);
$action = "mainpage.php?subject_id=" . $subject . "¬e_id=" . $content;
?>
<form method="post" action="<?php echo $action; ?>">
<input type="text" name="list_item" value="">
<input type="submit" name="new_item" value="New Item">
</form>
此外,您应该养成验证该数据的习惯。您可能想检查它们是否为整数。
关于PHP GET方法空间错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8662414/