Jump to content
Larry Ullman's Book Forums

Ch10 edit_user script with HTML select menu


Recommended Posts

Hi all,

After working through the edit_user script in chapter ten, I thought I would like to try my hand at retrieving user information through a select dropdown. As I will have ~5000 clients, working through the list manually would be something of a chore. I came up with the following;

$query = "SELECT on_programme, last_name, first_name, middle_name, id FROM constant_client WHERE on_programme=1 ";
$result = mysqli_query($conn, $query);

echo  '<form action="selected_client.php" method="get">
    <fieldset>';

echo '<p><label for="current_clients">Select Client by name: </label>
        <select id="current_clients" name="current_clients">
        <option> -- Select Client -- </option>';

        while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
          echo '<option>'.$row['id'].' '.ucwords($row['last_name']).', '.ucwords($row['first_name']).' '.ucwords($row['middle_name']).'</option>';  
        }

echo '</select>';
      
      echo '<input type="submit" name="submit" value="Go!">
<input type="hidden" name="id" value="'.$row['id'].'">';

The above populates the dropdown menu, but I am receiving an "array offset type null" error on submission of the form, because the $row['id'] variable doesn't appear to be set outside the while loop.

Any suggestions would be greatly appreciated.

Link to comment
Share on other sites

 Share

×
×
  • Create New...