Thanks for the replies guys.
I've added error_reporting(E_ALL ^ E_NOTICE); into the php file but it now doesn't report anything in the log file (but still errors on the front end) so i took it out again.
Below is the code in play.
PHP:
Code:
<?php
//set database variables
$host="localhost";
$user="test";
$password="user";
$database="test";
//connect to the database
mysql_connect($host, $user, $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
//Check to see if the checkboxes are ticked or unticked
$MonCheck = isset($_POST['MonCheck']) ? 1 : 0;
$TueCheck = isset($_POST['TueCheck']) ? 1 : 0;
$WedCheck = isset($_POST['WedCheck']) ? 1 : 0;
$ThuCheck = isset($_POST['ThuCheck']) ? 1 : 0;
$FriCheck = isset($_POST['FriCheck']) ? 1 : 0;
$SatCheck = isset($_POST['SatCheck']) ? 1 : 0;
$SunCheck = isset($_POST['SunCheck']) ? 1 : 0;
$MonMealCheck = isset($_POST['MonMealCheck']) ? 1 : 0;
$TueMealCheck = isset($_POST['TueMealCheck']) ? 1 : 0;
$WedMealCheck = isset($_POST['WedMealCheck']) ? 1 : 0;
$ThuMealCheck = isset($_POST['ThuMealCheck']) ? 1 : 0;
$FriMealCheck = isset($_POST['FriMealCheck']) ? 1 : 0;
$SatMealCheck = isset($_POST['SatMealCheck']) ? 1 : 0;
$SunMealCheck = isset($_POST['SunMealCheck']) ? 1 : 0;
$MonEveningMealCheck = isset($_POST['MonEveningMealCheck']) ? 1 : 0;
$TueEveningMealCheck = isset($_POST['TueEveningMealCheck']) ? 1 : 0;
$WedEveningMealCheck = isset($_POST['WedEveningMealCheck']) ? 1 : 0;
$ThuEveningMealCheck = isset($_POST['ThuEveningMealCheck']) ? 1 : 0;
$FriEveningMealCheck = isset($_POST['FriEveningMealCheck']) ? 1 : 0;
$SatEveningMealCheck = isset($_POST['SatEveningMealCheck']) ? 1 : 0;
$SunEveningMealCheck = isset($_POST['SunEveningMealCheck']) ? 1 : 0;
$MonOvernightCheck = isset($_POST['MonOvernightCheck']) ? 1 : 0;
$TueOvernightCheck = isset($_POST['TueOvernightCheck']) ? 1 : 0;
$WedOvernightCheck = isset($_POST['WedOvernightCheck']) ? 1 : 0;
$ThuOvernightCheck = isset($_POST['ThuOvernightCheck']) ? 1 : 0;
$FriOvernightCheck = isset($_POST['FriOvernightCheck']) ? 1 : 0;
$SatOvernightCheck = isset($_POST['SatOvernightCheck']) ? 1 : 0;
$SunOvernightCheck = isset($_POST['SunOvernightCheck']) ? 1 : 0;
//insert data from form
$insert="INSERT INTO mileageform
(EmployeeName,EmployeeRef,WeeksPerYear,MonTownFrom,MonPostcodeFrom,MonTownTo,MonPostcodeTo,MonMiles,TueTownFrom,TuePostcodeFrom,TueTownTo,TuePostcodeTo,TueMiles,WedTownFrom,WedPostcodeFrom,WedTownTo,WedPostcodeTo,WedMiles,ThuTownFrom,ThuPostcodeFrom,ThuTownTo,ThuPostcodeTo,ThuMiles,FriTownFrom,FriPostcodeFrom,FriTownTo,FriPostcodeTo,FriMiles,SatTownFrom,SatPostcodeFrom,SatTownTo,SatPostcodeTo,SatMiles,SunTownFrom,SunPostcodeFrom,SunTownTo,SunPostcodeTo,SunMiles,SumMiles,MonCheck,TueCheck,WedCheck,ThuCheck,FriCheck,SatCheck,SunCheck,MonHours,TueHours,WedHours,ThuHours,FriHours,SatHours,SunHours,SumHours,MonTravel,TueTravel,WedTravel,ThuTravel,FriTravel,SatTravel,SunTravel,MonMealCheck,TueMealCheck,WedMealCheck,ThuMealCheck,FriMealCheck,SatMealCheck,SunMealCheck,MonEveningMealCheck,TueEveningMealCheck,WedEveningMealCheck,ThuEveningMealCheck,FriEveningMealCheck,SatEveningMealCheck,SunEveningMealCheck,MonOvernightCheck,TueOvernightCheck,WedOvernightCheck,ThuOvernightCheck,FriOvernightCheck,SatOvernightCheck,SunOvernightCheck)
VALUES ('$EmployeeName','$EmployeeRef,'$WeeksPerYear','$MonTownFrom','$MonPostcodeFrom','$MonTownTo','$MonPostcodeTo','$MonMiles','$TueTownFrom','$TuePostcodeFrom','$TueTownTo','$TuePostcodeTo','$TueMiles','$WedTownFrom','$WedPostcodeFrom','$WedTownTo','$WedPostcodeTo','$WedMiles','$ThuTownFrom','$ThuPostcodeFrom','$ThuTownTo','$ThuPostcodeTo','$ThuMiles','$FriTownFrom','$FriPostcodeFrom','$FriTownTo','$FriPostcodeTo','$FriMiles','$SatTownFrom','$SatPostcodeFrom','$SatTownTo','$SatPostcodeTo','$SatMiles','$SunTownFrom','$SunPostcodeFrom','$SunTownTo','$SunPostcodeTo','$SunMiles','$SumMiles','$MonCheck','$TueCheck','$WedCheck','$ThuCheck','$FriCheck','$SatCheck','$SunCheck','$MonHours','$TueHours','$WedHours','$ThuHours','$FriHours','$SatHours','$SunHours','$SumHours','$MonTravel','$TueTravel','$WedTravel','$ThuTravel','$FriTravel','$SatTravel','$SunTravel','$MonMealCheck','$TueMealCheck','$WedMealCheck','$ThuMealCheck','$FriMealCheck','$SatMealCheck','$SunMealCheck','$MonEveningMealCheck','$TueEveningMealCheck','$WedEveningMealCheck','$ThuEveningMealCheck','$FriEveningMealCheck','$SatEveningMealCheck','$SunEveningMealCheck','$MonOvernightCheck','$TueOvernightCheck','$WedOvernightCheck','$ThuOvernightCheck','$FriOvernightCheck','$SatOvernightCheck','$SunOvernightCheck')";
//execute insert
$result = mysql_query($insert);
//validation
if ($result)
{
echo("<br>Thank you for your mileage form submission. Your form will be processed as soon as possible.");
}else
{
echo("<br>Your form has not been submitted. Please check the data and try again.");
}
?>
May seem a little bit messy due to the number of fields in the form (i'm sure there's a way to make it easier).
The fields i'm having trouble with are:
SumMiles
SumHours
The html for the form is below, which includes the calculation code for how to come up with those fields.
The sum values appear on the site when you type them live, but aren't posted for some reason.
I've had to split the code in three due to the length.
Code:
<?php
//Buffer larger content areas like the main page content
ob_start();
?>
<script type="text/javascript">
$(document).ready(function() {
$('.sigPad').signaturePad();
});
</script>
<script type="text/javascript">
$(document).ready(function(){
//iterate through each textboxes and add keyup
//handler to trigger sum event
$(".formmiles").each(function() {
$(this).keyup(function(){
calculateSum();
});
});
});
function calculateSum() {
var sum = 0;
//iterate through each textboxes and add the values
$(".formmiles").each(function() {
//add only if the value is number
if(!isNaN(this.value) && this.value.length!=0) {
sum += parseFloat(this.value);
}
});
//.toFixed() method will roundoff the final sum to 2 decimal places
$("#summiles").html(sum.toFixed(2));
}
</script>
<script type="text/javascript">
$(document).ready(function(){
//iterate through each textboxes and add keyup
//handler to trigger sum event
$(".formhours").each(function() {
$(this).keyup(function(){
calculateSum1();
});
});
});
function calculateSum1() {
var sum1 = 0;
//iterate through each textboxes and add the values
$(".formhours").each(function() {
//add only if the value is number
if(!isNaN(this.value) && this.value.length!=0) {
sum1 += parseFloat(this.value);
}
});
//.toFixed() method will roundoff the final sum to 2 decimal places
$("#sumhours").html(sum1.toFixed(2));
}
</script>
<script type="text/javascript">
$(document).ready(function(){
//iterate through each textboxes and add keyup
//handler to trigger sum event
$(".formtravel").each(function() {
$(this).keyup(function(){
calculateSum2();
});
});
});
function calculateSum2() {
var sum2 = 0;
//iterate through each textboxes and add the values
$(".formtravel").each(function() {
//add only if the value is number
if(!isNaN(this.value) && this.value.length!=0) {
sum2 += parseFloat(this.value);
}
});
//.toFixed() method will roundoff the final sum to 2 decimal places
$("#sumtravel").html(sum2.toFixed(2));
}
</script>
<script type="text/javascript">
<!--
function updatesum() {
document.sumform.sumtotal.value = (document.sumform.sumhours.value -0) + (document.sumform.sumtravel.value -0);
}
//-->
</script>
<table width="100%">
<tr>
<td valign="top">
<div class="SubMenuBig">
<img src="Images/Pages/2.png" style="top: 0px; position: relative; margin-left:-5px ; " class="SubMenuImage" />
<h2 id="ctl00_ContentPlaceHolder1_h1Hdr" class="H1Banner">Daily Mileage & Subsistence Expenses Claim Form</h2>
</div>
<table>
<tr>
<td align="left" colspan="4">
<p>
Please fully complete this form and submit to TJW Contract Solutions
<br>
Fields marked with an asterisk (*) are required
</p>
</td>
</tr>
</table>
<div class="SubMenuItemBig">
I posted two more replies to the thread but they are waiting for moderator approval before being posted for some reason.
Apologies that they may appear out of order!
[Thu Oct 11 22:59:09 2012] [error] [client x.x.x.x] PHP Notice: Undefined variable: SumMiles in /home/test/public_html/Beta/Scripts/formsubmit.php on line 46, referer: http://www.test.com/Beta/mileage3.php
[Thu Oct 11 22:59:09 2012] [error] [client x.x.x.x] PHP Notice: Undefined variable: SumHours in /home/test/public_html/Beta/Scripts/formsubmit.php on line 46, referer: http://www.test.com/Beta/mileage3.php
After I add error_reporting(E_ALL ^ E_NOTICE); to the php file, the error messages stop being logged to the log file and the front end doesn't display any errors either (apart from the if else error message I programmed into the php file, I.E. the data still doesn't insert).
hmmmm, OK keep it in the beginning of your file as is; it seems there is no problem with your PHP code, then change $result = mysql_query($insert); to $result = mysql_query($insert) or die(mysql_errors()); now see what MySQL errors you get.
Bookmarks