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

  • SEARCH
  • Home
  • 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 3279296
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:34:36+00:00 2026-05-17T19:34:36+00:00

I have a picture uplaod tool which reloads the page (which contains a form)

  • 0

I have a picture uplaod tool which reloads the page (which contains a form) whenever a picture is chosen.

I have this code to “remember” the drop list options selected, so basically I am creating options using php:

$posted_type=$row['9_type']; //From mysql db

$types = array('Clothes', 'Bags', 'Others');
$category_table .= "<select name='type' id='type'>";

foreach ($types as $type) 
{
$category_table .= "<option id='" . $type . "' value='" . $type . "' " . 
(($_POST['type'] == $type || $posted_type==$type)?'selected':'') . ">" . $type . "</option>\n";
}

This code has a problem, if the page is reloaded, and the “type” drop-list is changed, then there will be two “SELECTED” attributes added instead of one.

I need to have something like:

isset($_POST['type']) THEN add "SELECTED" and ignore the $posted_type variable comparison

Is there any short code for this?

I am pretty new to PHP, and it will take me a day just to change all categories and add a “if-case” just to check if the $_POST has been set already…

Anybody know of a good idea?

Thanks

  • 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-05-17T19:34:36+00:00Added an answer on May 17, 2026 at 7:34 pm

    Check the selected type before you enter the foreach loop:

    $selected = $posted_type;
    if (isset($_POST['type'])) {
        $selected = $_POST['type'];
    }    
    
    foreach ($types as $type) {
        $html .= '<option '
              .= 'id="' . $type . '" '
              .= 'value="' . $type . '" ';
    
        if ($selected == $type) {
            $html .= "selected";
        }
    
        $html .= '>'
              .= $type
              .= '</option>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which user enters data and upload a picture, when user
I have inherited some C# code. This code needs to upload a picture to
I have a picture in a DIV on site abc.com which is hosted elsewhere,
I have the picture box in which the image may be zoomed with different
I have a picture in res/drawable directory: res/drawable/picture.jpeg. Can I dynamically update this picture.jpeg
I have 3x3 picture boxes on a form, what I want to do is
I have a picture table which consists for users pictures Table Name:picture Columns: picture_id
I have a laughing problem : I upload a picture on my server. This
I have a picture upload inside a form... The file is a php file
Currently, I have an 'add your ad here' page, with a form. Now, the

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.