<HTML>
<style type="text/css">
<!--
.BoldText {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
}
.BigBoldText {
font-family: Arial, Helvetica, sans-serif;
font-size: 36px;
font-weight: bold;
}
-->
</style>
<body>
<?PHP
$PreviousDate = date("Y-m-d",strtotime($_POST["RecordDate"])-86400);
$SQLstring = "Update [DailyTotals] SET ";
$SQLstring = $SQLstring."[CityWater] = '".$_POST["CityUsage"]."'";
$SQLstring = $SQLstring." ,[RiverWater] = '".$_POST["RiverUsage"]."'";
$SQLstring = $SQLstring. " WHERE [DateAndTime] = '".$_POST["RecordDate"]."'";
$SQL1string = "DELETE FROM [WaterMeters] WHERE [DateAndTime] = '".$_POST["RecordDate"]."'";
$SQL2string = "INSERT INTO [WaterMeters] ([DateAndTime], [RiverWater], [CityWater]) Values (";
$SQL2string = $SQL2string."'".$_POST["RecordDate"]."','";
$SQL2string = $SQL2string.$_POST["NewRiverWaterReading"]."','";
$SQL2string = $SQL2string.$_POST["NewCityWaterReading"]."')";
// Connect to the SQL server and update the record
$db = mssql_connect("SQLSERVER\INSTANCE","sa","password") or die("Unable to connect to server");
mssql_select_db("Reporting");
mssql_query($SQLstring,$db) or die('<table width="450" border ="0" align="center" cellpadding="1"><tr>
Unable to save meter readings. Please check entered values.
</tr><tr align="center"><form name="frm" method="post" action="">
<input type="button" name="Button" value="Go back to water readings" onClick="history.go(-1)">
</form></tr>
</table>');
echo "<table width='450' border='0' align='center' cellpadding='1'>";
echo " <tr>";
echo " <td class='BoldText'>Daily totals table successfully updated for ".date("F d, Y",strtotime($PreviousDate))."<br>";
echo " City water usage = ".$_POST['CityUsage'].". River water usage = ".$_POST['RiverUsage'].". </td><br>";
echo " </tr>";
echo "</table>";
mssql_query($SQL1string,$db);
mssql_query($SQL2string,$db) or die('<table width="450" border ="0" align="center" cellpadding="1"><tr>
Unable to save meter readings. Please check entered values.
</tr><tr align="center"><form name="frm" method="post" action="">
<input type="button" name="Button" value="Go back to water readings" onClick="history.go(-1)">
</form></tr>
</table>');
echo "<table width='450' border='0' align='center' cellpadding='1'>";
echo " <tr>";
echo " <td class='BoldText'>Water meter history table successfully updated for ".date("F d, Y",strtotime($RecordDate))."<br>";
echo "City water reading = ".$_POST["NewCityWaterReading"].". River water reading = ".$_POST["NewRiverWaterReading"].". </td><br>";
echo " </tr>";
echo " <tr>";
echo " <td class='BigBoldText'> SUCCESS </TD> ";
echo " </tr>";
echo "</table>";
?>
<form name="form1" method="post" action="">
<div align="center">
<input type="button" name="Button" value="Close Window" onClick="window.close()">
<input type="button" name="Button" value="Go back to water readings" onClick="history.go(-1)">
<input type="button" name="Button" value="Go to capacity report" onClick="window.location='[URL unfurl="true"]http://www.mydomian.com'">[/URL]
</div>
</form>
</body></HTML>