i have listbox 1 which displays status , based on selection of status listbox 2 displays usernames. and based on username selected the textbox displays the email id.

its working fine till displaying user names in listbox 2 based on selected of status in listbox. but its not displaying the emailid based on selection of usernames and when i click on search for users button its refreshs the page and shows the intial page also want the text box to be displayed only on click the search for users button

<?php
//------------------------------------------------------------
// Part 1: Choosing a Status
//============================================================
 
// Initializes a list of acceptable statuses
$statusname_list = array();
$status_list[] = array();
 
$query_status = " SELECT status_type.status, status_type.status_name FROM status_type ";
 
       $result_status = mysql_query($query_status);
        confirm_query($result_status);
 
 
       $statusname_list[]=" ";
  while ($record = mysql_fetch_assoc($result_status)) {
          $statusname_list[] = $record['status_name'] ;
          $status_list[] =  $record['status'];       
        }
$status = $_GET['status_name'];
$user = $_GET['username'];
$emailid = "" ;
 
// A form for choosing the status
?>
<form method="get" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
    <input type="submit" name="status" value="Search for status:" />
    <select name="status_name" >
        <?php
 
        // Loops through the $status_list array
         foreach ($statusname_list as $value => $option)
        {
            // Sets an attribute to show the chosen status as selected
            $selected = ($status == $value) ? ' selected="selected"' : '';
 
            // Builds an option for each acceptable status
           echo '<option value="'.$value.'"'.$selected.'>'.$option.'</option>';
 
        }
        ?>
    </select>
 
 
 
<?php
 
// Part 2: Using the Chosen Status to Search the Database
//============================================================
 
 
$usernames = array();
$query = "SELECT username FROM users WHERE users.status = '{$status_list[$status]}'"; 
$result = mysql_query($query);
if ($result)
{
    while ($row = mysql_fetch_assoc($result))
    {
        $usernames[] = $row['username'];
    }
}
 
// If there are some usernames in the array...
if (count($usernames) > 0)
{
    ?>
    <p>Users with status: <?php echo $status_list[$status]; ?></p>
    <ul>
    <td>
 
    <input type="submit" name="users" "value="Search for user:" />
    <select name="username" >
        <?php
 
        // Loops through the $status_list array
         foreach ($usernames as $value => $option)
        {
            // Sets an attribute to show the chosen status as selected
            $selected = ($user == $value) ? ' selected="selected"' : '';
 
            // Builds an option for each acceptable status
           echo '<option value="'.$value.'"'.$selected.'>'.$option.'</option>';
 
        }
        ?>
    </select> 
 
    </td>
 
    </ul>
    <?php
}
else
{
 ?>
 <p>
 <select name="username" >
  <? echo '<option>'." ".'</option>'; ?></p>
 
<?php 
}
?>
 
<?
// Part 2: Using the Chosen username to Search the Database for emailid
$query_details = "SELECT users.emailid FROM users WHERE users.username = '{$usernames[$user]}' and users.status = '{$status_list[$status]}' ";
$result_details = mysql_query($query_details);
if ($result_details)
{ 
  $record_details = mysql_fetch_assoc($result_details);
  $emailid = $record_details['emailid'];
 }
 
 
?>
<? 
if ($emailid != "") {
?>
 
<td><input type="disabled" name="emailid" maxlength="30" value="<?php echo $emailid ?>" /></td>
</tr>
<?
}
 
?>
</form>

On line 74 there is an extra ". This could be making the form fail.

I didn't look at the rest of the code very much, so there might be another problem.

nope i removed wat u said it still giving no display in the text box....plz if i have coded it right?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.