I'm having the following problem: Ihave 3 dropdown lists. When I press the button I get 3 $_POST variables. Also, I have a function with 3 variables needed to get the outcome like this function(x,y,z) in wachtwoord dropdown list, and I save the options x,y,z in a serialized array as a history.
Everything works perfectly, but when I load the update page I want to unserialize the array, and extract the 3 values for each dropdown list, and I want to display the previews outcome before I change something and get the new. The problem is that with an if statement it locks the $_POST values and when I press the button it keeps the same without discarding the old ones first.
My update.php page:
echo '<div class="form-inline">
<div class="form-group">
<label for="name1">name1:</label>
<select name="name1[]" style="width:auto;" class="form-control">
<option value="0" '.((isset($_POST['name1'][0]) && $_POST['name1'][0] == 0)?'selected="selected"':'').'>option1</option>
<option value="3" '.((isset($_POST['name1'][0]) && $_POST['name1'][0] == 3)?'selected="selected"':'').'>option2</option>
</select>
<label for="name2">name2:</label>
<select name="name2[]" style="width:auto;" class="form-control">
<option value="option1" '.((isset($_POST['name2'][0]) && $_POST['name2'][0] == "option1")?'selected="selected"':'').'>option1</option>
<option value="option2" '.((isset($_POST['name2'][0]) && $_POST['name2'][0] == "option2")?'selected="selected"':'').'>option2</option>
</select>
<label for="name3">name3:</label>
<select name="name3[]" style="width:auto;" class="form-control">
<option value="0" '.((isset($_POST['name3'][0]) && $_POST['name3'][0] == 0)?'selected="selected"':'').'>optionA</option>
<option value="1" '.((isset($_POST['name3'][0]) && $_POST['name3'][0] == 1)?'selected="selected"':'').'>optionB</option>
<option value="2" '.((isset($_POST['name3'][0]) && $_POST['name3'][0] == 2)?'selected="selected"':'').'>optionC</option>
</select>
</div>
</div>';
My history array:
$history = unserialize($results[0]->history);
$name1 = $history[name1];
$name2 = $history[name2];
$name3 = $history[name3];
As I said, an if statement for one of three lists:
if(isset($name1) && $name1 == 0){$_POST['name1'][0] = 0;
}else{$_POST['name1'][0] = 3;}
To summarize: [page loads]->[dropdown lists are OK with the history values] -X->[change 1 or more dropdown lists and press the button keeps the old values and NOT the new ones.]
Could you please help me? Thanks in advance.