#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    How to get value from dropdown to variable in php


    hye i m new to php,kindly tell me how to get the selected value from dropdown in a variable for further action..
    the normal method is by $_GET or $_Post but its not working

    my code is below
    PHP Code:
    <form >
    Month: <select name="month" id="month">
      <option>januvary</option>
      <option>feb</option>
      <option>march</option>
      <option>april</option>
      <option>may</option>
      <option>june</option>
      <option>july</option>
      </select>
      <?php
     
    echo $_GET['month'];
      
    ?>
    but it is giving error undefined index month
  2. #2
  3. Known to taste like chicken
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    In front of my computer
    Posts
    399
    Rep Power
    312
    You have pretty much all the elements but it looks like you are trying to echo it ouf on the same script as the form is. You will need to submit the form to another page then it will be accessible.

    page1.php
    PHP Code:
    <form action="page2.php" method="get">
    Month: <select name="month" id="month">
      <
    option>january</option>
      <
    option>feb</option>
      <
    option>march</option>
      <
    option>april</option>
      <
    option>may</option>
      <
    option>june</option>
      <
    option>july</option>
      </
    select>
    <
    input type="submit" value="Next">
    </
    form
    page2.php
    PHP Code:
      <?php
     
    echo $_GET['month'];
      
    ?>
    note the extra info in the <form> tag and the submit button also.
    "Take thy beak from out my heart, and take thy form from off my door" - Homer J Simpson / Edgar Allan Poe

    Looking for a project Idea?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    i m not having a submit button.. it will not work with out submit button ?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    i m having all dropdown on same page
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    thanks its working can i ask another question here ? or should i start a new thread ?
  10. #6
  11. Known to taste like chicken
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    In front of my computer
    Posts
    399
    Rep Power
    312
    new questions should go in a new thread.
    Last edited by sir_drinxalot; December 28th, 2012 at 11:32 PM. Reason: it seems I fail at english.
    "Take thy beak from out my heart, and take thy form from off my door" - Homer J Simpson / Edgar Allan Poe

    Looking for a project Idea?

IMN logo majestic logo threadwatch logo seochat tools logo