Carbs Posted May 31, 2020 Share Posted May 31, 2020 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 More sharing options...
Larry Posted June 1, 2020 Share Posted June 1, 2020 I'm not sure what the hidden input is supposed to be doing but you can just change the SELECT menu to use the id and name of "id" and then the next page has access to the selected item. Link to comment Share on other sites More sharing options...
Carbs Posted June 1, 2020 Author Share Posted June 1, 2020 Larry, it's more that I don't know what I'm doing, but I'll give that a go. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts