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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:09:21+00:00 2026-06-13T20:09:21+00:00

I have following code in my php page, I’m trying to store the value

  • 0

I have following code in my php page,
I’m trying to store the value of the selection list to a variable in my php page.

Can someone kindly help on this?

    $state_list= <<<HTML <select name="state">
    <option value="0"></option>
    <option value="1">ok</option>
    <option value="2">not-ok</option>
    </select>
    HTML;

echo "<table>";
        while($row = mysql_fetch_array($result1))
          {
          echo "<tr>";
          echo "<td>" . $row['task'] . "</td>";
          echo "<td>" . $row['task_desc'] . "</td>";
          echo "<td>";  echo $state_list; echo "</td>";
          echo "</tr>";
          }
 echo "</table>";

        if(isset($_GET['state'])) {
        $stat=$_GET['state'];
        echo $stat;
        }
  • 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-13T20:09:22+00:00Added an answer on June 13, 2026 at 8:09 pm

    With your sample code, you’re storing the entire list into a variable in PHP (and it looks invalid, you’ll need to put the HTML on a second line, like this):

    $state_list= <<<HTML
    <select name="state"> <option value="0"></option> <option value="1">ok</option> <option value="2">not-ok</option> </select>
    HTML;
    

    If you’re trying to get the actual submitted value of the select list (once the form is submitted), you can access it either through $_GET['state'], or $_POST['state'], depending on the method your form is submitting such as:

    $state = $_POST['state'];
    

    UPDATE (outputting the form?)
    From your most-recent edit, it looks like you’re not putting the actual select list inside of a <form></form> block (which you’ll need to do to actually submit the value). A simple example is like this:

    echo '<form method="get">';
    echo $state_list;
    echo '<input type="submit" value="Submit Form" />';
    echo '</form>';
    

    I’ve also included a submit-button to give you a way to, well, submit the form =P.

    However, you’re going to encounter an issue with this method because you need a separate select-list for every row in your results. Because of this, you’ll actually need a separate form for every row in your results (or some extra javascript code, but we’ll leave that one for a rainy day).

    Also, since you need a value for each individual row, you’ll need a second (hidden) field to tell which row was selected. Here’s a block of sample code that should be able to do this for you:

    while($row = mysql_fetch_array($result1)) {
        echo "<tr>";
        echo "<td>" . $row['task'] . "</td>";
        echo "<td>" . $row['task_desc'] . "</td>";
        echo "<td>";
            echo '<form method="get"><input type="hidden" name="task" value="' . $row['task'] . '" />';
            echo $state_list;
            echo '<input type="submit" value="Submit" /></form>';
        echo "</td>";
        echo "</tr>";
    }
    

    The problem with this method is that you’ll have a Submit button on every single row. While this will work and I’ve seen it in numerous places before, it’s not really visually appealing. If this is unsuitable for your needs, you could update the select list to auto-submit when a value is selected. To do this, just update the <select> tag to: <select name="state" onchange="this.form.submit()">. If you do this, you could remove the submit-button from the output loop above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in a php page <div class=vmenu> <div class=first_li><span >Add
I have the following PHP code, and for the life of me I can't
Hi I have the following code of my PHP page that shows me the
I have the following code inside the body of my index.php page: echo Begin
I have the following html code for my php page. <span id=edit_button_<?php echo $row[$id];
Currently, I have the following PHP code loaded every time the page is refreshed.
I have following code in my php page. These are two tabs Inbox and
I have the following code in my index.php page: // Write the resulting JSON
I am using wordpress and on the page sidebar.php I have the following code:
In a php page I have following code: if($_REQUEST['c']!=) // I get error on

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.