I'm currently trying to create a gym website for a PHP project I have to do for my class, however on the membership calculator I cannot get it to display something right.
Where it says "For a ______ membership..." I want it to say the type (single or couple) as opposed to the number value. However I need the number value (45, 75) to calculate the monthly cost so this is why I tried using if and elseif statements before the line where it prints. However with what I currently have it only displays Single as $membership but still calculates correctly.
Any help would be appreciated. Heres my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Membership Calculator</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<?php
// In case register_globals is disabled.
$type = $_POST['type'];
$months = $_POST['months'];
function Months() {
print '<select name="months">';
for ($months = 1; $months <= 12; $months++) {
print "\n<option value=\"$months\">$months</option>";
}
print '</select>';
}
$total = $type * $months;
?>
</head>
<body>
<center><img src="logo.jpg" border="0" /></center>
<p>To calculate an estimate of a monthly membership please use the form below.</p>
<form method="post">
<table border="0" align="center">
<tr>
<td align="right">Membership Type:</td>
<td><select name="type"><option value="45" name="single">Single ($45)</option><option name="couple" value="75">Couple ($75)</option></select></td>
</tr>
<tr>
<td align="right">Months:</td>
<td>
<?php
months();
?>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="Submit" id="Submit" value="Calculate" /> <input type="reset" name="reset" id="reset" value="Reset" /></td>
</tr>
</table>
</form><br /><br />
<hr width="70%" />
<?php
if ($type = 45) {
$membership = 'Single';
} elseif ($type = 75) {
$membership = 'Couple';
}
print "<p align=\"center\">For a <u>$membership</u> membership for <u>$months</u> month(s) your total cost is: <u>$$total</u>.</p>";
?>
</body>
</html>