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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:02:06+00:00 2026-06-01T19:02:06+00:00

<form method=post> <select name=box[]> <option value=1 <?php if ($_POST[‘box[0]’] == 1) echo selected=\selected\;?>>1</option> <option

  • 0
<form method="post">
    <select name="box[]">
        <option value="1" <?php if ($_POST['box[0]'] == "1") echo "selected=\"selected\";"?>>1</option>
        <option value="2" <?php if ($_POST['box[0]'] == "2") echo "selected=\"selected\";"?>>2</option>
        <option value="3" <?php if ($_POST['box[0]'] == "3") echo "selected=\"selected\";"?>>3</option>
    </select>
    <p>
    <select name="box[]">
        <option value="1" <?php if ($_POST['box[1]'] == "1") echo "selected=\"selected\";"?>>1</option>
        <option value="2" <?php if ($_POST['box[1]'] == "2") echo "selected=\"selected\";"?>>2</option>
        <option value="3" <?php if ($_POST['box[1]'] == "3") echo "selected=\"selected\";"?>>3</option>
    </select>
    <p>
    <input type="submit" value="Submit">
</form>

When I use box names “box1” and “box2”, it works without a problem. What am I doing wrong?

****** EDIT ********

Thanks a lot for your comments, but I actually found the solution myself, even if it doesn’t make much sense. Instead of using $_POST[‘box’][0] and [1] at the if statement, I simply used $box[0] and [1]. Even though it’s posted, apparently php sees it as a normal array, and not as some kind of $_POST-array! Working code:

<form method="post">
    <select name="box[]">
        <option value="1" <?php if ($box[0] == "1") echo "selected='selected'";?>>1</option>
        <option value="2" <?php if ($box[0] == "2") echo "selected='selected'";?>>2</option>
        <option value="3" <?php if ($box[0] == "3") echo "selected='selected'";?>>3</option>
    </select>
    <p>
    <select name="box[]">
        <option value="1" <?php if ($box[1] == "1") echo "selected='selected'";?>>1</option>
        <option value="2" <?php if ($box[1] == "2") echo "selected='selected'";?>>2</option>
        <option value="3" <?php if ($box[1] == "3") echo "selected='selected'";?>>3</option>
    </select>
    <p>
    <input type="submit" value="Submit">
</form>
  • 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-01T19:02:07+00:00Added an answer on June 1, 2026 at 7:02 pm

    Thanks a lot for your comments, but I actually found the solution myself, even if it doesn’t make much sense. Instead of using $_POST[‘box’][0] and [1] at the if statement, I simply used $box[0] and [1]. Even though it’s posted, apparently php sees it as a normal array, and not as some kind of $_POST-array! Working code:

    <form method="post">
        <select name="box[]">
            <option value="1" <?php if ($box[0] == "1") echo "selected='selected'";?>>1</option>
            <option value="2" <?php if ($box[0] == "2") echo "selected='selected'";?>>2</option>
            <option value="3" <?php if ($box[0] == "3") echo "selected='selected'";?>>3</option>
        </select>
        <p>
        <select name="box[]">
            <option value="1" <?php if ($box[1] == "1") echo "selected='selected'";?>>1</option>
            <option value="2" <?php if ($box[1] == "2") echo "selected='selected'";?>>2</option>
            <option value="3" <?php if ($box[1] == "3") echo "selected='selected'";?>>3</option>
        </select>
        <p>
        <input type="submit" value="Submit">
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that looks like this. <form action=index.php method=post> <select name=dropdownOption> <option
Client code is pretty simple: <form action=DDServlet method=post> <input type=text name=customerText> <select id=customer> <option
I have an HTML form: <form action='process.php' method='post'> <input type='checkbox' name='check_box_1' /> Check me!<br>
This is where i put a popup box into echo <tr><td>.$set['Name'].</td><td>.$set['Position'].</td><td><select name='aaa'><option value='default'>Not Share</option><option
and with this form: (select * from mp3 aktif = '0') <form name=form method=post>
<html> <head> <title>ADD URL Sources</title> </head> <body> <form action=Test1.jsp method=post> <br><br><select name=source onchange=> <option
In a php-script i have a form, method is post, action-attribute is empty, which
I have this simple Select box that is suppose to store the selected value
My HTML form is something like as follows <form id=form1 name=form1 method=post action=> number:
I have a html form with the data by this post method 'form id='form1'

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.