Have an account? Sign in
Login  Register  Facebook
Pass array key and values into mysql
I have followed your code but the values are not being added to the database.

I think the problem is in the code for the select box.

my original code is

	if(!empty($level)) {
		foreach($level as $value) {
			echo "<option value="{$value}"";
			echo getSticky(2,'user_level',$value);
			echo ">{$value}</option>";
		}
	}
I have tried to amend it to the following code but no luck:
	if(!empty($level)) {
		foreach($level as $key => $value) {
			echo "<option value="{$value}"";
			echo getSticky(2,'user_level',$value);
			echo ">{$value}</option>";
		}
	}
$level = array(
   1 => 'User',
   5 => 'Admin'
);
you have recommended the following also but without the sticky form fileds that are required also
foreach($level as $key => $val) {
    echo "<option value="$key">$val</option>";
}
but the following echo is missing from code
echo getSticky(2,'user_level',$value);
echo ">{$value}</option>";
I think the foreach loop needs to be modified to show sticky form filed and than close the </option> tag. I need to dispaly the $value and pass the $key at the same time on the following code
echo "<option value="{$value}"";
Started: September 22, 2011 Latest Activity: September 22, 2011 php mysql
1 Answer
Please, look carefully after quotation marks
<?php echo "<option value="$key">$val</option>";
is not valid. repaired like this:
<?php echo "<option value=\"" . $key . "\">{$val}</option>";
or like this:
<?php echo "<option value=\"{$key}\">{$val}</option>";

Posted: MacOS
In: September 22, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer