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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:13:07+00:00 2026-06-06T02:13:07+00:00

I have a form named reg.php and its action is reg.php , i want

  • 0

I have a form named reg.php and its action is reg.php , i want the selected dropdown value when clicked on submit to remain selected , what i have done so far is given below

I have checked the questions that are posted but i couldnt match it with my code

<?php
if( $_POST['registerbtn']){
$selected_value = $_POST['selectID'];
$query = mysql_query("SELECT  linecard_name FROM selection WHERE select_id = '$selected_value'");
$rows=mysql_fetch_assoc($query); 
$linecard_name= $rows['linecard_name'];
$sql = "SELECT select_id, linecard_name FROM selection " . "ORDER BY linecard_name";
$rs = mysql_query($sql);

while($rownw = mysql_fetch_array($rs)){
if(  $rownw['linecard_name'] == $linecard_name)  {
$options = "<option  selected =selected  value=".$rownw['select_id']."> " .$rownw['linecard_name']. " </option> ";
}
}
}

require("./connect.php");
$sql = "SELECT select_id, linecard_name FROM selection ". "ORDER BY linecard_name";
$rs = mysql_query($sql);
while($rownw = mysql_fetch_array($rs)){
$options .= "<option value = ".$rownw['select_id']." > ".$rownw['linecard_name']. " </option> ";
} 
mysql_close() ;

$form = "<form action='./reg.php'  method='post'> 
<table>
<tr>
<td>  </td>
<td>  <font color='red'> $errormsg </font> </td> 
</tr>

<tr>
<td> Select  Linecard </td> 
<td> <Select name='selectID' >  <option value = '0'>  Select  from here </option> $options  </select></td> 
</tr>

<tr> 
<td  > <input type='submit' name='registerbtn' value='Register' />   </td> 
</tr> 
</table> 
echo $form;

The select statements before the register button is clicked is for filling the dropdown from the database,
I just want the selected items to remain selected when the particular selection is done by the user and register button is clicked ,
in which case my code fills the dropdown again but now with the user selected item as selected but without clearing the previous items filled in the dropdown i.e before the register button is clicked,
Please help

  • 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-06T02:13:09+00:00Added an answer on June 6, 2026 at 2:13 am

    I find that it’s cleanest to do it with a variable, like this:

    while($rownw = mysql_fetch_array($rs)){
      $selected = '';
      if ($rownw['select_id'] == $selected_value){
        $selected = 'selected="selected"';
      }
      $options .= "<option value = ".$rownw['select_id']." $selected > ".$rownw['linecard_name']. " </option> ";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table named Categories . I want to create a form
I have a Create new account page. The form is in page named Register.php
Hi I have a form and the action is submitting into a script named
I have a window form named form1 and on that I want to show
What i have done till now was to store the dropdown selected data into
i have a form that contains checkboxes. I've named the checkboxes as stream[], so
I have a Windows Form application with a button named loginBtn and a label
I have n number of text fields named in the form Question...... How can
Let's say I have a file named output1 How to match just digits form
I have the following form: <form name="quickAdd" action="" method="post" onsubmit="return quickAddProcess(this);"> <input type="hidden" name="quickAddFields[module]"

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.