I haven't been using PHP for a long time so I need a bit of help.
I've created a form to collect a person's details and then calculate total cost of a few items (Membership - the select box and Game Day Accessories - with the checkboxes) However I have no idea how to calculate the costs. I also need to know how to post these details to a new page. Can anyone help me out?
This is my code so far:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<!-- Minus AutoDato -->
<title>Membership Details</title>
<META NAME="Generator" CONTENT="Stone's WebWriter 3.5">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<!--
body {
background-color: #9900FF;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
} }
//-->
</script>
</head>
<body>
<!-- inserting data in a database from a form -->
<!-- For this assignment I had problems using functions to add up the price, I tried my best -->
<h2> Membership Details </h2>
<form enctype='multipart/form-data' action='insertData.php' method='post' onSubmit="MM_validateForm('strFirstname','','R','strSurname','','R', '','strPostcode','','NisNum','strPhone','','R','strEmail','','RisEmail');return document.MM_returnValue">
<p><label for='strFirstname'>First Name: </label>
<input name='strFirstname' type='text' id='strFirstname'/></p>
<p><label for='strSurname'>Surname: </label>
<input name='strSurname' type='text' id='strSurname'/></p>
<p><label for='strSuburb'>Suburb: </label>
<input name='strSuburb' type='text' id='strSuburb'/></p>
<p><label for='strState'>State: </label>
<select name='strState' >
<option> Select </option>
<option> Victoria </option>
<option> New South Wales </option>
<option> Australian Capital Territory </option>
<option> South Australia </option>
<option> Northern Territory </option>
<option> Western Australia </option>
<option> Queensland </option>
<option> Tasmania </option>
</select>
</p>
<p><label for='strPostcode'>Postcode: </label>
<input name='strPostcode' type='text' id='strPostcode'/></p>
<p><label for='strPhone'>Phone: </label>
<input name='strPhone' type='text' id='strPhone'/></p>
<p><label for='strEmail'>Email: </label>
<input name='strEmail' type='text' id='strEmail'/></p>
<p><label for='strType'>Membership Type: </label>
<select name='strType' >
<option> Choose </option>
<option> Social $880 </option>
<option> Gold $640</option>
<option> General $325 </option>
</select>
</p>
<p>
<label> Game Day Accessories: </label>
<input name="Scarf" type="checkbox" value="" />
<label> Scarf ($15)<label>
</label>
<input name="Beanie" type="checkbox" value="" />
<label> Beanie ($10)<label>
</label>
<input name="Cushion" type="checkbox" value="" />
<label> Cushion ($20)<label>
</label>
<input name="Medallion" type="checkbox" value="" />
<label> Medallion ($35)<label>
</label>
</p>
<p><input type='submit' name = "Add Member" value="Submit">
<label>
<input type="reset" name="Reset" id="button" value="Clear">
</label>
<p/>
</form>
<?php
?>
</body>
</html>