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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:28:04+00:00 2026-05-21T11:28:04+00:00

I have a simple PHP Array called $categories that looks like this: Array (

  • 0

I have a simple PHP Array called $categories that looks like this:

Array
(
[Closed] => P1000
[Open] => P1001
[Pending] => P1002
[In Progress] => P1003
[Requires Approval] => P1004
)

I’ve got a simple HTML form that has a drop down list for one field that I would like to use the array for the options, however I only want it do show the text (e.g. Closed, Open, Pending, In Progress and Requires Approval) as the options in the drop down list but store the associated key for that option (e.g. P1000, P1001 etc) which is then sent as a POST value when the form is submitted.

The HTML for the form field so far is:

<select name="category_id">
<option value=""></option>
<?php foreach($categories as $category) {$category = htmlspecialchars($category);?>
<option value="<?php echo $category; ?>"><?php echo $category; ?></option>
<?php
}
?>
</select>

I can get it to display either the text or the ID’s but not the text and store the ID. Hopefully this is something simple that someone can point me in the right direction.

Many thanks,
Steve

  • 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-21T11:28:05+00:00Added an answer on May 21, 2026 at 11:28 am

    You’ve forgot about $value tag. You were pasting Category name twice, instead of value. You should do that:

    <select name="category_id">
    <option value=""></option>
    <?php 
        #                             !vCHANGEv!
        foreach($categories as $category => $value) 
        {
           $category = htmlspecialchars($category); 
           echo '<option value="'. $value .'">'. $category .'</option>';
        }
    ?>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a table called my_table that looks like this: id |
I have a php function that brings in a simple arraycollection (called QuestionSeries) to
I'm pulling a content from PHP array and I have a situation like this:
I have a simple php script on a server that's using fsockopen to connect
I have this simple php script <?php echo '<pre>'; // Outputs all the result
So I have a PHP class called router that takes the URL and explodes
I have a page called send.email.php which sends an email - pretty simple stuff
I have a page called send.email.php which sends an email - pretty simple stuff
In my webapp I have a page called display.php. The script in this page
On the page 'selecteditems.php' I have a form like this: <form method=POST name=selecteditems action=nextpage.php>

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.