首先,我在HTML文档中有一个选择选项
<form action="Journey.php" method="post">
<select name = "Startpoint">
<optgroup label = "Start point">
<option value = "GrimesDyke">GrimesDyke</option>
<option value = "SeacroftRingRoad">SeacroftRingRoad</option>
<option value = "WykeBeck">WykeBeck</option>
<option value = "FfordeGrene">FfordeGrene</option>
<option value = "St.JamesHospital">St.JamesHospital</option>
.........
我确定动作是使用post方法将数据传递给Journey.php文件以执行某些算法,但是当我点击浏览器中的提交按钮时,它显示了我的整个PHP代码....所以我决定像这样进行一些测试:
Journey.php
<?php
if(isset($_POST['submit'])){
$selected = $_POST['Startpoint']; // Storing Selected Value In Variable
echo "You have selected :" .$selected; // Displaying Selected Value
}
?>
这一次,它没有显示任何内容,我正在尝试做的是,将一个$ selected文件中的Startpoint值传递给php文件并在屏幕上回显它,但它仍然无法正常工作
我在网上查了很多例子但老实说我看不出我做错了什么,请指出我的错误并告诉我如何才能做到正确,非常感谢你。
答案 0 :(得分:1)
我很久以前在php上写过,但是我记得'submit'
表中没有$_POST
键。请尝试检查'Startpoint'
密钥。
答案 1 :(得分:0)
这对我有用:
<?php
if(isset($_POST['submit'])){
$selected = $_POST['startpoint']; // Storing Selected Value In Variable
echo "You have selected: " . $selected; // Displaying Selected Value
};
?>
<form action="" method="post">
<select name = "startpoint">
<optgroup label = "Start point">
<option value = "GrimesDyke">GrimesDyke</option>
<option value = "SeacroftRingRoad">SeacroftRingRoad</option>
<option value = "WykeBeck">WykeBeck</option>
<option value = "FfordeGrene">FfordeGrene</option>
<option value = "St.JamesHospital">St.JamesHospital</option>
<input type="submit" name="submit" value="Submit">
</form>