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.

3
  • 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. Commented Apr 26, 2016 at 7:32
  • May I know your submit button <code>? Commented Apr 26, 2016 at 7:32
  • Possible duplicate of Using $_POST to get select option value from HTML Commented Apr 26, 2016 at 7:34

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.