Jump to content
Larry Ullman's Book Forums

Chapter 17 Update User Language


Recommended Posts

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

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

 Share

×
×
  • Create New...