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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:17:10+00:00 2026-06-03T23:17:10+00:00

What i have done till now was to store the dropdown selected data into

  • 0

What i have done till now was to store the dropdown selected data into the database , what i now would like is based on the username typed in the textbox and clicked on search button , the dropdown item to be selected is to be the data stored in the database along with a list of values which user should be able to choose if he wishes .

I just want to know how to replace the text Select from here with the selected data coming from the database as well as allow the user to edit the data as he wants in the dropdown and save it again in the database once he clicks the submit button .

Code While storing data is as follows

<?php
if( $_POST['registerbtn']){
$getuser=    mysql_real_escape_string(trim($_POST['user']));
$selected_value = $_POST['selectID'];
if($selected_value != 0){
require("./connect.php");
$query=mysql_query("SELECT * FROM user_details WHERE username='$getuser'");
$numrows= mysql_num_rows($query);
if($numrows == 0) { 
mysql_query("INSERT INTO user_details  VALUES (  '','$getuser','$selected_value')");
}
 else
$errormsg = "There is already a user with that username ." ;
mysql_close();
}
else
 $errormsg = "You  must select a linecard";
}
//code to fill dropdown 
require("./connect.php");
$sql = "SELECT select_id, linecard_name FROM selection ". "ORDER BY linecard_name";
$rs = mysql_query($sql);
$options = "<option value = '0'>  Select  from here </option>";
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>  Username  </td>
<td>  <input type='text' name='user'  value='$getuser' />  </td>
</tr>

<tr>
<td> Select  Linecard </td>
<td>  <Select name='selectID' > $options  </select> </td>
</tr>

<tr>
<td>   </td>
<td>  <input type='submit' name='registerbtn' value='Register' />  </td>
</tr>

</form>";

echo $form;
?>      

Code while retrieving the data from the database to the dropdown based on username written in textbox is as follows

<?php
if( $_POST['savebtn']){
$search = $_POST['search'];
if($search == '' )
{
$errormsg1 = "Enter something in the search box";
}
else
{
require("./connect.php");
$query = mysql_query("SELECT  * FROM user_details  WHERE  username = '$search'");
$numrows= mysql_num_rows($query);
$rows=mysql_fetch_assoc($query);
if($numrows == 1)
{
$getuser = $rows['username'];
$select_id= $rows['linecard_id'];
//selection table where linecard_name is stored along with select_id   for the linecard_name to be displayed 
$query1  = mysql_query("SELECT *  FROM selection  WHERE  select_id = '$select_id' ") ;
$rows1=mysql_fetch_assoc($query1);
$linecard_name= $rows1['linecard_name'];
echo $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( $select_id == $rownw['select_id'])  {
echo $select_id;
$options .= "<option value = ". $select_id ." > " .$linecard_name. " </option> ";
}
}

}
else
$errormsg1 = "Username was Not found";
mysql_close() ;
}
}

?>

<?php
$form ="<form action='ad.php' method='post' id='search' >
<div class='place'>
<tr>
<td>  </td>
<td>  <font color='red' > $errormsg1 </font> </td>
</tr>

<div class='frm2'> <input  type='text'  size='15'  value='$search'  name='search'    /> </div>
<div class='frm3'>      <input type='submit'   name='savebtn'  /> </div>
<div class='clear'> </div>
</div> 
</form>";
echo $form;
?>

<?php
require("./connect.php");
$sql = "SELECT select_id, linecard_name FROM selection "."ORDER BY linecard_name";
$rs = mysql_query($sql);
$options = "<option value = '0'>  Select  from here </option>";
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>  Username  </td>
<td>  <input type='text' name='user'  value='$getuser' />  </td>
</tr>

<tr>
<td> Select  Linecard </td>
<td>  <Select name='selectID' > $options  </select> </td>
</tr>
<tr>
<td>   </td>
<td> <input type='submit' name='savebtn' value='Save' />   </td>
</tr>
</form>";
echo $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-03T23:17:12+00:00Added an answer on June 3, 2026 at 11:17 pm

    You could store the options into a vairable, let’s call it $options and then insert it into your $form variable. Finally you can echo it wherever you want.

    <?php
    require("./connect.php");
    $sql = "SELECT select_id, linecard_name FROM selection ". "ORDER BY linecard_name";
    $rs = mysql_query($sql);
    
    $options = "<option value= '0' >  Select  from here </option>";
    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>  Username  </td>
    <td>  <input type='text' name='user' />  </td> 
        </tr> 
    
    <tr>
    <td> Select  Linecard </td> 
    <td> <Select name='selectID'> $options </select>
    </tr> 
    
    <tr>
    <td>   </td>
    <td> <input type='submit' name='registerbtn' value='Register' />   </td> 
    </tr>
    
    </table> 
    </form>"; 
    
    echo $form;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code shows below what i have done till now. Now what i need
I have to put thousand separator between numbers. I have done till now: Input
Have done some research and found some stuff that may be helpful. I would
I am not new to Subversion, but I have up till now used Tortoise
I have few scripts loaded by cron quite often. Right now I don't store
Have done some working samples using Backbone Router, but is there a way to
I have done automated UI testing before on a major WPF project and it
I have done some pre processing for dft , and i am trying to
I have done already a lot of small (and also bigger reports) with report
I have done a lot of looking around on the overflow, and on google,

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.