The following code is about 10 years old and has worked perfectly until recently. Over the last 12 months the select has been producing a value of 1 instead of the value of $cost or $membercost. However it only happens intermittently: 26 times out of 3000 registrations to be exact.
One colleague has pointed out that $chosencost_1 is never declared which many be the issue. How can it be declared when it depends on the choice made by the select? $chosencost_1 is first declared on the page that follows the one with the web form. What's most baffling is why has this code worked fine in the past and only recently become a problem? Could it be a browser/OS issue? Or a PHP version issue? We are using v5.5.27. CODE
The following variables are passed from a previous page (cost, member cost):
$cost = '';
if (isset($_REQUEST['cost']) && is_numeric($_REQUEST['cost'])) {
$cost = floatval($_REQUEST['cost']);
}
$membercost = '';
if (isset($_REQUEST['membercost']) && is_numeric($_REQUEST['membercost'])) {
$membercost = floatval($_REQUEST['membercost']);
}
//etc etc there are many other cost options
On this page which contains a web form, browsers use an html select to choose a course cost:
<select name="choosecost1" size="1" value="">
<option value=""></option>
<?php if ($cost !='') { ?>
<option value="<?php echo $cost; ?>" <?php if($chosencost_1 == $cost) echo 'selected="selected"'; ?>='<?php if($chosencost_1 == $cost) echo 'selected="selected"'; ?>'>Cost:<?php echo '$' . number_format($cost, 2 , '.' , ' '); ?></option>
<?php } ?>
<?php if ($membercost !='') { ?>
<option value="<?php echo $membercost; ?>" <?php if($chosencost_1 == $membercost) echo 'selected="selected"'; ?>='<?php if($chosencost_1 == $membercost) echo 'selected="selected"'; ?>'>Cost to Members:<?php echo '$' . number_format($membercost, 2 , '.' , ' '); ?></option>
<?php } ?>
<!--etc etc there are lots of other options-->
</select>
choosecost1 is passed to the next page where it becomes $chosencost_1
eg $chosencost_1 = $_POST['choosecost1'];