0

first, i've got a select option in a HTML document

<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>
.........

i determine the action is to pass the data using post method to Journey.php file in order to perform some algorithm, but when i click on the submit button in the browser it shown me my entire php code.... so i decided to run a few tests like this:

Journey.php
<?php
if(isset($_POST['submit'])){
$selected = $_POST['Startpoint'];  // Storing Selected Value In Variable
echo "You have selected :" .$selected;  // Displaying Selected Value
}
?>

this time, it displayed nothing, what i'm trying to do is, to store the Startpoint's value passed to the php file in a $selected variable and echo it on the screen, but it's still not working

i checked many examples online but honestly i can't see what i did wrong, please point out my mistake and show me how exactly i can make it right, thank you very much.

A.Y
  • 137
  • 1
  • 9
  • 1
    First, please post the HTML of the submit button. It should have < input type.... name = "submit" /> Second, you could try print_r($_POST) in Journey.php and see the list of all POST data, also whether you're getting 'Startpoint' there. – Indrasis Datta Apr 26 '16 at 07:32
  • May I know your submit button ? – Maths RkBala Apr 26 '16 at 07:32
  • Possible duplicate of [Using $\_POST to get select option value from HTML](http://stackoverflow.com/questions/17139501/using-post-to-get-select-option-value-from-html) – manniL Apr 26 '16 at 07:34

2 Answers2

1

I wrote on php long time ago, but as I remember there is no 'submit' key in the $_POST table. Try to check for 'Startpoint' key instead.

Mk Km
  • 94
  • 6
0

This works for me:

<?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>
RasmusGlenvig
  • 765
  • 6
  • 18