passing data from echo drop down list to another page

hi expert,

I am new in php, I would like a question regarding to passing data from echo drop down list to another page.
for example, I am doing echo a drop down list in php and how I able to pass the selected option value to another page. normally , when I am using name of drop down list as a linkage to get the value.<?php <select name='option' id='option' > ? > .
LVL 2
rolandmyAsked:
Who is Participating?
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Your php renders the html.  Assuming you can get rendered output like below.  (Note the code from insoftservice above is a bit off on the closing tag for the select tag)

<select name="option" id="option">
     <option value="123">item 123</option>
     <option value="124">item 124</option>
     <option value="124">item 124</option>
</select>

Open in new window


To get this to another page you can use a form or ajax.  Using a form you can send a post or a get.

<form method="post" action="somepage.php">
     <select name="option" id="option">
          <option value="123">item 123</option>
          <option value="124">item 124</option>
          <option value="124">item 124</option>
    </select>
    <button type="submit">Submit</button>
</form>

Open in new window

In the above sample you are sending a post and therefor can capture the data using $_POST["variable"]
$selected_item = $_POST["option"]

Open in new window

<form method="get" action="somepage.php">
     <select name="option" id="option">
          <option value="123">item 123</option>
          <option value="124">item 124</option>
          <option value="124">item 124</option>
    </select>
    <button type="submit">Submit</button>
</form>

Open in new window

In the above sample you are sending a get an and therefor can capture the data using $_GET["variable"].   The get will send the form data to the url.
$selected_item = $_GET["option"]

Open in new window

0
 
InsoftserviceCommented:
I would suggest to read some documents from w3schools and some blogs for PHP it would be more beneficial for you.
Please check the below code which would help you to pass data from one page to other by using post method
<form action="http://mydomain.com/page.php" method="post"> <br />
    <select> name="website_string" 
        <option value="" selected="selected"></option>
    <option VALUE="abc"> ABC</option>
    <option VALUE="def"> def</option>
        <option VALUE="hij"> hij/option>   
    </select>
    <input type="submit" name="website_string"  >
</form>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.