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 7887821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:40:49+00:00 2026-06-03T05:40:49+00:00

I am pretty new to PHP and am having a question about dropdown lists.

  • 0

I am pretty new to PHP and am having a question about dropdown lists. I am trying to get the list to pull from the database and populate the value when a user edits a form but it is not currently working. There are a few examples of this exact same thing on here but I can’t quite get it working, it is likely a syntax error on my end…

Here is my code:

echo '<p><label>Is this project targeted toward?</label><select name="proj_targ_tow"><option value="Select...">Select...</option><option value="National Site">National Site</option><option="Local Site">Local Site</option><option value="Regional Site">Regional Site</option><option value="Other">Other</option></select></p>';

And here is the logic to populate the value from the database, the row I am trying to pull from is ‘proj_targ_tow’…

    $typesArray = array ( 'Select..', 'National Site', 'Local Site', 'Regional Site', 'Other' );
$selectedType = '';
echo 'as;ldfjas;lfmawoiealknfsliu2047a   ' . $row['proj_targ_tow'] . '<br />';
foreach($typesArray as $value){
    if($value == $row['proj_targ_tow']) {
        $selectedType = 'selected="selected"';
} 
echo '<option value="' . $value . '" ' . $selectedType . '>' . $value . '</option>';
}

Can any of you coding gods out there help me out?

  • 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-03T05:40:50+00:00Added an answer on June 3, 2026 at 5:40 am

    It looks to me like the $value in your echo statement is out of scope… what happens when you do this?

    $typesArray = array ( 'Select..', 'National Site', 'Local Site', 'Regional Site', 'Other' );
    
    foreach($typesArray as $value){
        $selectedType = '';
    
        if($value == $row['proj_targ_tow'])
            $selectedType = 'selected="selected"';
    
        echo '<option value="' . $value . '" ' . $selectedType . '>' . $value . '</option>';
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am pretty new to PHP and I am trying to make an inventory
I'm pretty new to php but i'm learning pretty fast, I have a question
I am pretty new to PHP and I am trying to use the googlechartphplib...
I'm pretty new to PHP so sorry about the possible misuse of terminology here.
In PHP I am having difficulty trying to extract row data from one SQL
I'm pretty new to PHP, DOM, and the PHP DOM implementation. What I'm trying
I'm pretty new to PHP, I'm working in WordPress but I don't think that
I'm pretty new to PHP and have a String which contains an HTML page.
I'm pretty new to Java and Spring 3 (used primarily PHP the past 8
I've done a fair bit of mysql php programming but am pretty new to

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.