Forum Moderators: coopster
<select name="programme">
<option value="" selected="">Choose Programme:</option>
<option value="7.00">3 Months</option>
<option value="11.00">6 Months</option>
<option value="85.00">12 Months</option>
<option value="900.00">24 Months</option>
</select> <select name="programme">
<option value="" selected="">Choose Programme:</option>
<option value="7.00" id="3" name="3 months">3 Months</option>
</select> <?php
//collecting variables from previous form
$quote = $_POST["programme"];
$make = $_POST["make"];$reg = $_POST["reg"];$serial = $_POST["serial"];
$title = $_POST["title"];$in = $_POST["initial"];$sur = $_POST["surname"];
$add1 = $_POST["address1"];$add2 = $_POST["address2"];$add3 = $_POST["address3"];$code = $_POST["postcode"];
$tel = $_POST["tel"];$email = $_POST["email"];
?> <form method="post" action="testa.php">
<input name="programme" type="hidden" value="<?php echo "$quote";?>" />
<input name="make" type="hidden" value="<?php echo "$make";?>" />
<input name="reg" type="hidden" value="<?php echo "$reg";?>" />
<input name="serial" type="hidden" value="<?php echo "$serial";?>" />
<input name="title" type="hidden" value="<?php echo "$title";?>" />
<input name="initial" type="hidden" value="<?php echo "$in";?>" />
<input name="surname" type="hidden" value="<?php echo "$sur";?>" />
<input name="address1" type="hidden" value="<?php echo "$add1";?>" />
<input name="address2" type="hidden" value="<?php echo "$add2";?>" />
<input name="address3" type="hidden" value="<?php echo "$add3";?>" />
<input name="postcode" type="hidden" value="<?php echo "$code";?>" >
<input name="tel" type="hidden" value="<?php echo "$tel";?>"/>
<input name="email" type="hidden" value="<?php echo "$email";?>"/>
</form>
<?php
function getDB()
{
return array(
1 => array('cost' => 7, 'months' =>3),
2 => array('cost' => 11, 'months' =>6),
3 => array('cost' => 85, 'months' =>12),
4 => array('cost' => 900, 'months' =>24)
);
}
function makeSelect($arr)
{
$str='';
foreach($arr AS $key=>$row)
{$str.='<option value="'.$key.'">'.$row['months'].' Months</option>/n';}
return $str;
}
$db=getDB();
if($_POST){echo('You selected: '.$db[$_POST['programme']]['months'].' Months');}
else
{
echo('
<form method="post" action="submit.php">
<input type="submit" />
<select name="programme">
<option value="0" selected="">Choose Programme:</option>
'.makeSelect($db).'
</select>
</form>');
}
?>
<?php
function getDB()
{
return array(
1 => array('cost' => 7, 'months' =>3),
2 => array('cost' => 11, 'months' =>6),
3 => array('cost' => 85, 'months' =>12),
4 => array('cost' => 900, 'months' =>24)
);
}
$db=getDB();
if($_POST){echo('You selected: '.$db[$_POST['programme']]['months'].' Months');}
?>
page2.php
<?php
$month = $_POST['programme'];
$value = $price_array[$month];
$price_array[3] = '7.00';
$price_array[6] = '11.00';
$price_array[12] = '85.00';
$price_array[24] = '900.00';
foreach ($price_array as $month=>$value)
{
echo '<option value="'.$month.'">'.$month.' Months</option>';
echo $value;
}
?>
- first declare your array ($price_array)
- then get the $month value from the post data ($month = $_POST['programme']
- then you can have $value = $price_array[$month]; (7.00 for example)
[edited by: omoutop at 11:02 am (utc) on Aug 13, 2010]
<?php
$month = $_POST['programme'];
$value = $price_array[$month];
$price_array[3] = '7.00';
$price_array[6] = '11.00';
$price_array[12] = '85.00';
$price_array[24] = '900.00';
foreach ($price_array as $month=>$value)
{
echo 'You chose '.$month.' months which costs £'.$value.'<br><br>';
}
?>
<?php
$price_array[3] = '7.00';
$price_array[6] = '11.00';
$price_array[12] = '85.00';
$price_array[24] = '900.00';
$month = $_POST['programme']; // this is submitted from page 1
$value = $price_array[$month];
echo 'Month: '.$month.' <br><br> Cost: '.$value.' ';
?>