Jump to content
Larry Ullman's Book Forums

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";

	echo '</select>';
	if (array_key_exists('lang', $profile_errors)) echo '<span class="help-block">' . $profile_errors['lang'] . '</span>';
echo '</div>';


Link to post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...