Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8973607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:29:05+00:00 2026-06-15T18:29:05+00:00

i have a drop down list in my php code. Im trying to get

  • 0

i have a drop down list in my php code. Im trying to get the value to stay selected after the page has been submitted using a submit button ( the form action calls another php script however the code block below is in the same php script as the form). I tried this but it doesn’t do what i needed to. Any suggestions would help.

//getting value from database
$dropDownVal=$row['player'];
////
echo "<td bgcolor=#7FFF00><select name='DropDown".$row['_id']."' >;
<option value=\"1\"  if ($dropDownVal==1) selected=\"selected\">Select </option>;
<option value=\"2\"  if ($dropDownVal==2) selected=\"selected\">Johnson</option>;
<option value=\"3\"if ($dropDownVal==3) selected=\"selected\">Reed</option>;
<option value=\"4\"if ($dropDownVal==4) selected=\"selected\">Suggs</option>;
<option value=\"5\"if ($dropDownVal==5) selected=\"selected\">Flacco</option>;
<option value=\"6\"if ($dropDownVal==6) selected=\"selected\">Rice</option>;
</select>";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:29:07+00:00Added an answer on June 15, 2026 at 6:29 pm

    Chris is essentially correct.

    If you are submitting this in a form that uses POST variables.

    Then if you then modified your logic for setting the $dropDownVal to use the $_POST variable you should get what you want:

    If you’re submitting your form via GET, just change all references of $_POST to $_GET.

    Heres the full code for reference in a single page:

    <html>
    <head></head>
    <?php
    if (!empty($_GET['Dropdown'])) {
        $dropDownVal = $_GET['Dropdown'];
    } else {
        $dropDownVal = 1;
    }
    ?>
    <form method="get" action="testing.php">
        <select name="Dropdown" >;
            <option value="1" <?php if ($dropDownVal==1) echo 'selected="selected"'; ?>>Select </option>;
            <option value="2" <?php if ($dropDownVal==2) echo 'selected="selected"'; ?>>Johnson</option>;
            <option value="3" <?php if ($dropDownVal==3) echo 'selected="selected"'; ?>>Reed</option>;
            <option value="4" <?php if ($dropDownVal==4) echo 'selected="selected"'; ?>>Suggs</option>;
            <option value="5" <?php if ($dropDownVal==5) echo 'selected="selected"'; ?>>Flacco</option>;
            <option value="6" <?php if ($dropDownVal==6) echo 'selected="selected"'; ?>>Rice</option>;
        </select>
        <input type="submit" name="submit" value="Submit Form" />
    </form>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Php I have wrote the drop down list box code. for Edit employee
In a PHP page I have a drop-down list that triggers the jQuery change
I have a parent page which has a drop down list in it. using
I have a PHP based form. It has a drop down list which fetches
I have one drop down list in my page, which contains two options. What
I have a drop down list that has options that need to be passed
I have a drop-down list hardcoded in an MVC View User Control page and
I have a drop down list that is populated with data in the code
I am trying to get a drop-down list to display column data containing countries
I need some help please, I have a PHP page with a drop down

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.