Hi,
I have a simple form that the user will input two datapoints into : the current date and their weight. That information will be put into a database. Along with that, I would like to calculate their BMI (Body Mass Index) based on their weight, and insert that info to the database as well. Then want to present a page with a chart containing all their datapoints to date. The flow would be like this:
- Input Date
- Input Weight
- Hit Submit
- Calculate BMI
- Insert Date, Weight, BMI values into database
- Present page with all Date/Weight/BMI values to date
How's the best way to do this? Here's the current code I have:
<?php
$db = mysql_connect("localhost", "xxxxx", "xxxxx");
mysql_select_db("fitness",$db);
if ($submit) {
$sql = "INSERT INTO mark (date,weight) VALUES ('$date','$weight')";
$result = mysql_query($sql);
header ("Location: http://www.somewhere.com/status.php");
} else {
?>
<html>
<head>
<title>Weight Input</title>
</head>
<body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0" bgcolor="#FFFFFF">
<!-- Start Submission Form -->
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2>
<FORM METHOD="post" ACTION="<?php echo $PHP_SELF?>">
<TR>
<TD ColSpan=1 RowSpan=1 Align=Left>
Date:
</TD>
<TD ColSpan=1 RowSpan=1 Align=Left>
<INPUT TYPE="text" NAME="date" SIZE=10>
</TD>
</TR>
<TR>
<TD ColSpan=1 RowSpan=1 Align=Left>
Weight:
</TD>
<TD ColSpan=1 RowSpan=1 Align=Left>
<INPUT TYPE="text" NAME="weight" SIZE=10>
</TD>
</TR>
<TR>
<TD ColSpan=2 RowSpan=1 Align=Center>
<INPUT TYPE="submit" NAME="submit" VALUE="Submit"> <INPUT TYPE="reset" VALUE="Reset">
</TD>
</TR>
</FORM>
</TABLE>
<?php
} // end if
?>
</body>
</html>
Any help would be greatly appreciated!
Thanks,
Mark