Jacques Posted June 17, 2020 Share Posted June 17, 2020 Hi Larry, I want to assign the value from $_POST['lang'] = $row[3]; to the below select form, but can't get it to work. Any recommendations? Thank you! // Language drop down menu: echo '<div class="form-group'; if (array_key_exists('lang', $profile_errors)) echo ' has-error'; echo '"><select name="lang" id="lang" class="form-control"> <option>' . $words['profile_form_6'] . '</option>'; // Retrieve all the languages and add to the pull-down menu: $q = "SELECT id, lang FROM languages WHERE status='Active' ORDER BY lang ASC"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['lang']) && ($_POST['lang'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } } mysqli_free_result($r); echo '</select>'; if (array_key_exists('lang', $profile_errors)) echo '<span class="help-block">' . $profile_errors['lang'] . '</span>'; echo '</div>'; Link to comment Share on other sites More sharing options...
Larry Posted June 17, 2020 Share Posted June 17, 2020 The code you have looks okay to me. If it's not working, I'd start by looking at the HTML source of the output to see if there's something useful there. Also, should you be using POST or GET? Link to comment Share on other sites More sharing options...
Jacques Posted June 17, 2020 Author Share Posted June 17, 2020 Hi Larry, Thank you for your response. I changed the $_POST to assign the value for each form field with: value="' . $row[0] . '", value="' . $row[1] . '" etc. All the input form fields display the correct data from the database as previously, except for the select fields. The select fields also now also gives the following error: (An error occurred in script 'C:\xampp\htdocs\...' on line 246: Trying to access array offset on value of type null). When I assign the select value to an input field, the correct data is displayed in the field. I couldn't find anything helpful on Stack Overflow. Link to comment Share on other sites More sharing options...
Recommended Posts