jordanking
Programmer
- Sep 8, 2005
- 351
hello,
I have a form that captures user input to insert into a mysql database. I am using php 5 and mysql 5. The form consists of text fields and list menus. I also have a function to capture and validate user input before the insert record function is called. If there are errors the insert function is ignored. The code for handling the user input is also within the same php page. I have inserted code to capture the post values so that if there are errors in the user input the user fields do not get reset to blank on page update. The text fields work great. I am having problems with the list menue values.
I have a block of code that I have inserted in order to capture the $_POST['listmenu'] value and insert a "selected="selected" value within the option tag so that when the form is refreshed after errors are detected the list menu retains the selected value. Shown below
this returns the following html:
the problem is that I am trying to run a conditional statement within anoth list menu's code that inclues an or operator "||". And for some reason it is always evaluating to true. The following is the php code followed by the html output
all of the above option line conditional statments that include || are evaluating to true. However i have confirmed that the $_POST['service_id'] is correct and is only a 1 or a 2 etc... If I take out the || operator it works.
Can anyone tell my why these are evaluating to true.
Thanks in advance
JK
I have a form that captures user input to insert into a mysql database. I am using php 5 and mysql 5. The form consists of text fields and list menus. I also have a function to capture and validate user input before the insert record function is called. If there are errors the insert function is ignored. The code for handling the user input is also within the same php page. I have inserted code to capture the post values so that if there are errors in the user input the user fields do not get reset to blank on page update. The text fields work great. I am having problems with the list menue values.
I have a block of code that I have inserted in order to capture the $_POST['listmenu'] value and insert a "selected="selected" value within the option tag so that when the form is refreshed after errors are detected the list menu retains the selected value. Shown below
Code:
<select name="city" id="city">
<option value="6"<?php if (isset($_POST['city']) && $_POST['city']==6){echo ' selected="selected"' ;} ?>>Beaumont</option>
<option value="9"<?php if (isset($_POST['city']) && $_POST['city']==9){echo ' selected="selected"' ;} ?>>Devon</option>
<option value="1"<?php if(empty($_POST)){ echo ' selected="selected"' ;}elseif (isset($_POST['city']) && $_POST['city']==1){echo ' selected="selected"' ;} ?>>Edmonton</option>
<option value="8"<?php if (isset($_POST['city']) && $_POST['city']==8){echo ' selected="selected"' ;} ?>>Ft. Saskatchewan</option>
<option value="7"<?php if (isset($_POST['city']) && $_POST['city']==7){echo ' selected="selected"' ;} ?>>Leduc</option>
<option value="2"<?php if (isset($_POST['city']) && $_POST['city']==2){echo ' selected="selected"' ;} ?>>Sherwood Park</option>
<option value="5"<?php if (isset($_POST['city']) && $_POST['city']==5){echo ' selected="selected"' ;} ?>>Spruce Grove</option>
<option value="3"<?php if (isset($_POST['city']) && $_POST['city']==3){echo ' selected="selected"' ;} ?>>St. Albert</option>
<option value="4"<?php if (isset($_POST['city']) && $_POST['city']==4){echo ' selected="selected"' ;} ?>>Stony Plain</option>
</select>
Code:
<select name="city" id="city">
<option value=""></option>
<option value="6">Beaumont</option>
<option value="9">Devon</option>
<option value="1" selected="selected">Edmonton</option>
<option value="8">Ft. Saskatchewan</option>
<option value="7">Leduc</option>
<option value="2">Sherwood Park</option>
<option value="5">Spruce Grove</option>
<option value="3">St. Albert</option>
<option value="4">Stony Plain</option>
</select>
the problem is that I am trying to run a conditional statement within anoth list menu's code that inclues an or operator "||". And for some reason it is always evaluating to true. The following is the php code followed by the html output
Code:
<select name="service_id" id="service_id">
<option value=""></option>
<option value="1"<?php if(empty($_POST)){ echo ' selected="selected"' ;}elseif (isset($_POST['service_id']) && $_POST['service_id']==1||2||3){echo ' selected="selected"' ;} ?>>Up</option>
<option value="2"<?php if (isset($_POST['service_id']) && $_POST['service_id']==8||9||10){echo ' selected="selected"' ;} ?>>Down</option>
<option value="3"<?php if (isset($_POST['service_id']) && $_POST['service_id']==15||16||17){echo ' selected="selected"' ;} ?>>Fix</option>
<option value="4"<?php if (isset($_POST['service_id']) && $_POST['service_id']==43){echo ' selected="selected"' ;} ?>>Cnd Up</option>
<option value="5"<?php if (isset($_POST['service_id']) && $_POST['service_id']==44){echo ' selected="selected"' ;} ?>>Cnd Down</option>
</select>
Code:
<select name="service_id" id="service_id">
<option value=""></option>
<option value="1" selected="selected">Up</option>
<option value="2" selected="selected">Down</option>
<option value="3" selected="selected">Fix</option>
<option value="4">Cnd Up</option>
<option value="5">Cnd Down</option>
</select>
all of the above option line conditional statments that include || are evaluating to true. However i have confirmed that the $_POST['service_id'] is correct and is only a 1 or a 2 etc... If I take out the || operator it works.
Can anyone tell my why these are evaluating to true.
Thanks in advance
JK