Reputation: 1
I have a program that I'm writing that is using a <select>
in HTML. When I submit the form, and execute the PHP script, I'm using a $_POST
to grab the selected option from the HTML page. However, it is only passing a "1" every time. I've tried selecting different values, but it is always selecting 1. Here's the code:
HTML:
<form id="form_22942" class="appnitro" method="post" action="../process/process.php">
<div class="form_description"></div>
</li>
<li class="section_break">
<h3>Deployment Constraints</h3>
<p></p>
</li>
<li id="li_11">
<label class="description" for="element_11">Corporate Policies and Procedures: </label>
<div>
<select class="element select medium" id="element_11" name="element_11">
<option value="" selected="selected"></option>
<option value="1" >Flexible</option>
<option value="2" >Fixed</option>
</select>
</div>
</form>
PHP (process.php):
$corp_policy = $_POST['element_11'];
$entityname2 = "corp_policy";
if ($corp_policy = '1') {
echo "<center>Corporate policies and procedures are flexible.<center>";
$corp_policy_text = "Flexible";
}
else if ($corp_policy = '2') {
echo "<center>Corporate policies and procedures are fixed.<center>";
$corp_policy_text = "Fixed";
}
Upvotes: 0
Views: 1482
Reputation: 1
<select class="element select medium" id="element_11" name="element_11">
<option disabled selected > -- select an option -- </option>
<option value="" selected="selected"></option>
<option value="1" >Flexible</option>
<option value="2" >Fixed</option>
</select>
It works for me
Upvotes: 0
Reputation: 2412
You should be using these: (==
)
if ($corp_policy == '1') {
echo "<center>Corporate policies and procedures are flexible.<center>";
$corp_policy_text = "Flexible";
}
else if ($corp_policy == '2') {
echo "<center>Corporate policies and procedures are fixed.<center>";
$corp_policy_text = "Fixed";
}
instead of these: (=
)
if ($corp_policy = '1') {
echo "<center>Corporate policies and procedures are flexible.<center>";
$corp_policy_text = "Flexible";
}
else if ($corp_policy = '2') {
echo "<center>Corporate policies and procedures are fixed.<center>";
$corp_policy_text = "Fixed";
}
Upvotes: 0
Reputation: 2374
You are assigning 1 to $corp_policy instead of comparing the two operands.
Use == or ===
Check the doc for more informations: http://php.net/manual/en/language.operators.comparison.php
Upvotes: 3