WLC Data Entry Source

This source code uses forms to store and change data in the database.

[code lang="PHP"]
			 0)
					{
						//Function saves the weight and the percentage to the database
						switch ($weeknum)
						{
						case 1:
							$sql="UPDATE wlc_spring SET weight01 = '$weight' WHERE personID = '$person' ";
							if (!mysql_query($sql,$thiscon))
							  {
							  die('Error: ' . mysql_error());
							  }
							$sql="UPDATE wlc_spring SET pct01 = '$pct' WHERE personID = '$person' ";
							if (!mysql_query($sql,$thiscon))
							  {
							  die('Error: ' . mysql_error());
							  }
						break;
						case 2:
							$sql="UPDATE wlc_spring SET weight02 = '$weight' WHERE personID = '$person' ";
							if (!mysql_query($sql,$thiscon))
							  {
							  die('Error: ' . mysql_error());
							  }
							$sql="UPDATE wlc_spring SET pct02 = '$pct' WHERE personID = '$person' ";
							if (!mysql_query($sql,$thiscon))
							  {
							  die('Error: ' . mysql_error());
							  }
						break;
						//This pattern continues for 11 members...
						default:
						  echo "

No week number selected

"; } } } //End Function************************************************************************ //!!!!!!! NOTE - This code still needs to be cleaned up!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! $name = $_REQUEST['name'] ; $startweight = $_REQUEST['startweight'] ; $type = $_REQUEST['type'] ; $week = $_REQUEST['week'] ; $name1wt = $_REQUEST['name1wt'] ; $name2wt = $_REQUEST['name2wt'] ; $name3wt = $_REQUEST['name3wt'] ; $name4wt = $_REQUEST['name4wt'] ; $name5wt = $_REQUEST['name5wt'] ; $name6wt = $_REQUEST['name6wt'] ; $name7wt = $_REQUEST['name7wt'] ; $name8wt = $_REQUEST['name8wt'] ; $name9wt = $_REQUEST['name9wt'] ; $name10wt = $_REQUEST['name10wt'] ; $name11wt = $_REQUEST['name11wt'] ; $name12wt = $_REQUEST['name12wt'] ; $dataset = TRUE; $con = mysql_connect("wlc2010.db.3538652.hostedresource.com","wlc2010","Thanks1926"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("wlc2010", $con); //If the user entered data from the new form, enter it into the table if this is the first save. if ($type=="new") { if($dataset == TRUE) { echo "

INVALID ENTRY - The data in the database has been locked.

"; } else { $sql="INSERT INTO wlc_spring (name, startWeight) VALUES ('$name','$startweight')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "

" . $name . " record added

"; } } //************************************************************************************* // New User Form if($dataset == FALSE) { echo "

New User Data Entry

Name: Starting Weight:

"; } //************************************************************************************* // Weekly Entry Form // If the user already chose the Week if($type == "weekly") { //Give the user the option to enter the Weights for the Names echo "

Weekly Data Entry

You have chosen Week " . $week . "

"; //Get the names from the database $result = mysql_query("SELECT * FROM wlc_spring WHERE personID='1'"); $name1 = mysql_fetch_array($result); $result = mysql_query("SELECT * FROM wlc_spring WHERE personID='2'"); $name2 = mysql_fetch_array($result); $result = mysql_query("SELECT * FROM wlc_spring WHERE personID='3'"); $name3 = mysql_fetch_array($result); //This continues for 11 members... echo "
//This continues for 11 members...
Name Weight
" . $name1['name'] . "
" . $name2['name'] . "
" . $name3['name'] . "
"; } else { //Allow the user to choose the week echo "

Weekly Data Entry

Week:
"; } if($type == "clear") { //Enter the data from the last weekly form entry //Get the start weight from the database $result = mysql_query("SELECT * FROM wlc_spring WHERE personID='1'"); $row = mysql_fetch_array($result); $start1 = $row['startWeight']; $result = mysql_query("SELECT * FROM wlc_spring WHERE personID='2'"); $row = mysql_fetch_array($result); $start2 = $row['startWeight']; $result = mysql_query("SELECT * FROM wlc_spring WHERE personID='3'"); $row = mysql_fetch_array($result); $start3 = $row['startWeight']; $result = mysql_query("SELECT * FROM wlc_spring WHERE personID='4'"); $row = mysql_fetch_array($result); //This continues for 11 members... //Calculate the percentage for the table $pct1 = (($start1-$name1wt)/$start1)*100; $pct2 = (($start2-$name2wt)/$start2)*100; $pct3 = (($start3-$name3wt)/$start3)*100; //This continues for 11 members... //Enter the correct week switch ($week) { case 1: savetodb("1", $con, $name1wt, $pct1, "1"); savetodb("1", $con, $name2wt, $pct2, "2"); savetodb("1", $con, $name3wt, $pct3, "3"); savetodb("1", $con, $name4wt, $pct4, "4"); savetodb("1", $con, $name5wt, $pct5, "5"); savetodb("1", $con, $name6wt, $pct6, "6"); savetodb("1", $con, $name7wt, $pct7, "7"); savetodb("1", $con, $name8wt, $pct8, "8"); savetodb("1", $con, $name9wt, $pct9, "9"); savetodb("1", $con, $name10wt, $pct10, "10"); savetodb("1", $con, $name11wt, $pct11, "11"); echo "

Record adding complete

"; break; case 2: savetodb("2", $con, $name1wt, $pct1, "1"); savetodb("2", $con, $name2wt, $pct2, "2"); savetodb("2", $con, $name3wt, $pct3, "3"); savetodb("2", $con, $name4wt, $pct4, "4"); savetodb("2", $con, $name5wt, $pct5, "5"); savetodb("2", $con, $name6wt, $pct6, "6"); savetodb("2", $con, $name7wt, $pct7, "7"); savetodb("2", $con, $name8wt, $pct8, "8"); savetodb("2", $con, $name9wt, $pct9, "9"); savetodb("2", $con, $name10wt, $pct10, "10"); savetodb("2", $con, $name11wt, $pct11, "11"); echo "

Record adding complete

"; break; //This continues for 10 weeks... default: echo "

No week number selected

"; } } //************************************************************************************* //************************************************************************************* //Create the Weight Table $result = mysql_query("SELECT * FROM wlc_spring"); echo "

Data in the Database

"; while($row = mysql_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Name St. Wk 1 Wk 2 Wk 3 Wk 4 Wk 5 Wk 6 Wk 7 Wk 8 Wk 9 Wk 10
" . $row['name'] . "" . $row['startWeight'] . "" . $row['weight01'] . "" . $row['weight02'] . "" . $row['weight03'] . "" . $row['weight04'] . "" . $row['weight05'] . "" . $row['weight06'] . "" . $row['weight07'] . "" . $row['weight08'] . "" . $row['weight09'] . "" . $row['weight10'] . "
"; mysql_close($con); ?> [/code][code]
[/code][code lang="PHP"] [/code][code]
[/code]

Author: Steph

Share This Post On

Pin It on Pinterest

Share This