When the data is entered and submitted, the form doesn't push the data to the database table. Could not find the error.
My table Structure is :
CREATE TABLE `maintenance` (
`id` int(11) NOT NULL,
`time1` time(6) NOT NULL,
`date1` date NOT NULL,
`dateofchange` date NOT NULL,
`sender` varchar(50) NOT NULL,
`reciver` varchar(50) NOT NULL,
`vehicleno` varchar(20) NOT NULL,
`skm` int(50) NOT NULL,
`engineoil` double NOT NULL,
`coolant` double NOT NULL,
`brakefluid` double NOT NULL,
`battery` double NOT NULL,
`tyre` double NOT NULL,
`airfilter` double NOT NULL,
`electrical` double NOT NULL,
`wheel` double NOT NULL,
`dieselfilter` double NOT NULL,
`vehiclebody` double NOT NULL,
`others` varchar(500) NOT NULL,
`costothers` double NOT NULL,
`totalcost` double NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
<?php
session_start();
error_reporting(0);
include('includes/config.php');
if(strlen($_SESSION['alogin'])==0)
{
header('location:index.php');
}
else{
if(isset($_POST['submit']))
{
date_default_timezone_set('Asia/Calcutta');
$time1 = date('H:i:s');
$date1 = date('Y-m-d');
$dateofchange=$_POST['dateofchange'];
$vehicleno=$_POST['vehicleno'];
$skm=$_POST['skm'];
$engineoil=(float)$_POST['engineoil'];
$coolant=(float)$_POST['coolant'];
$brakefluid=(float)$_POST['brakefluid'];
$battery=(float)$_POST['battery'];
$tyre=(float)$_POST['tyre'];
$airfilter=(float)$_POST['airfilter'];
$electrical=(float)$_POST['electrical'];
$wheel=(float)$_POST['wheel'];
$dieselfilter=(float)$_POST['dieselfilter'];
$vehiclebody=(float)$_POST['vehiclebody'];
$others=$_POST['others'];
$costothers=(float)$_POST['costothers'];
$user=$_SESSION['alogin'];
$reciver= 'Admin';
$notitype='Data Sent';
$totalcost=$engineoil+$coolant+$brakefluid+$battery+$tyre+$airfilter+$electrical+$wheel+$dieselfilter+$vehiclebody+$costothers;
$sql="insert into maintenance (time1,date1,dateofchange,sender,reciver, vehicleno,skm,engineoil,coolant,brakefluid,battery,tyre,airfilter,electrical,wheel,dieselfilter,vehiclebody,others,costothers,totalcost) values (:time1,:date1,:dateofchange,:user,:reciver,:vehicleno,:skm,:engineoil,:coolant,:brakefluid,:battery,:tyre,:airfilter,:electrical,:wheel,:dieselfilter,:vehiclebody,:others,:costothers,:totalcost)";
$query = $dbh->prepare($sql);
$query-> bindParam(':time1', $time1, PDO::PARAM_STR);
$query-> bindParam(':date1', $date1, PDO::PARAM_STR);
$query-> bindParam(':dateofchange', $dateofchange, PDO::PARAM_STR);
$query-> bindParam(':user', $user, PDO::PARAM_STR);
$query-> bindParam(':reciver', $reciver, PDO::PARAM_STR);
$query-> bindParam(':vehicleno', $vehicleno, PDO::PARAM_STR);
$query-> bindParam(':skm', $skm, PDO::PARAM_INT);
$query-> bindParam(':engineoil', $engineoil, PDO::PARAM_STR);
$query-> bindParam(':coolant', $coolant, PDO::PARAM_STR);
$query-> bindParam(':brakefluid', $breakfluid, PDO::PARAM_STR);
$query-> bindParam(':battery', $battery, PDO::PARAM_STR);
$query-> bindParam(':tyre', $tyre, PDO::PARAM_STR);
$query-> bindParam(':airfilter', $airfilter, PDO::PARAM_STR);
$query-> bindParam(':electrical', $electrical, PDO::PARAM_STR);
$query-> bindParam(':wheel', $wheel, PDO::PARAM_STR);
$query-> bindParam(':dieselfilter', $dieselfilter, PDO::PARAM_STR);
$query-> bindParam(':vehiclebody', $vehiclebody, PDO::PARAM_STR);
$query-> bindParam(':others', $others, PDO::PARAM_STR);
$query-> bindParam(':costothers', $costothers, PDO::PARAM_STR);
$query-> bindParam(':totalcost', $totalcost, PDO::PARAM_STR);
$query->execute();
$msg="Data Sent";
}
?>
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<meta name="theme-color" content="#3e454c">
<title>Edit Profile</title>
<!-- Font awesome -->
<link rel="stylesheet" href="css/font-awesome.min.css">
<!-- Sandstone Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- Bootstrap Datatables -->
<link rel="stylesheet" href="css/dataTables.bootstrap.min.css">
<!-- Bootstrap social button library -->
<link rel="stylesheet" href="css/bootstrap-social.css">
<!-- Bootstrap select -->
<link rel="stylesheet" href="css/bootstrap-select.css">
<!-- Bootstrap file input -->
<link rel="stylesheet" href="css/fileinput.min.css">
<!-- Awesome Bootstrap checkbox -->
<link rel="stylesheet" href="css/awesome-bootstrap-checkbox.css">
<!-- Admin Stye -->
<link rel="stylesheet" href="css/style.css">
<script type= "text/javascript" src="../vendor/countries.js"></script>
<style>
.errorWrap {
padding: 10px;
margin: 0 0 20px 0;
background: #dd3d36;
color:#fff;
-webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
}
.succWrap{
padding: 10px;
margin: 0 0 20px 0;
background: #5cb85c;
color:#fff;
-webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
}
</style>
</head>
<body>
<?php
$sql = "SELECT * from admin_maintenance;";
$query = $dbh->prepare($sql);
$query->execute();
$result=$query->fetch(PDO::FETCH_OBJ);
$cnt=1;
?>
<?php include('includes/header.php');?>
<div class="ts-main-content">
<?php include('includes/leftbar.php');?>
<div class="content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">Edit Info</div>
<?php if($error){?><div class="errorWrap"><strong>ERROR</strong>:<?php echo htmlentities($error); ?> </div><?php }
else if($msg){?><div class="succWrap"><strong>SUCCESS</strong>:<?php echo htmlentities($msg); ?> </div><?php }?>
<div class="panel-body">
<form method="post" class="form-horizontal" enctype="multipart/form-data">
<div class="form-group">
<input type="hidden" name="user" value="<?php echo htmlentities($result->email); ?>">
<label class="col-sm-2 control-label">Vehicle No<span style="color:red">*</span></label>
<div class="col-sm-4">
<?php
try
{
$sql1 = "select vehicleno from vehicle";
$projresult = $dbh->query($sql1);
$projresult->setFetchMode(PDO::FETCH_ASSOC);
}
catch (PDOException $e)
{
die("Some problem getting data from database !!!" . $e->getMessage());
}
echo '<select name="vehicleno" id="vehicleno" class="form-control" >';
while ( $row = $projresult->fetch() )
{
echo '<option value="'.$row['vehicleno'].'">'.$row['vehicleno'].'</option>';
}
echo '</select>';
?>
</div>
<label class="col-sm-2 control-label">Kilometer of Change<span style="color:red">*</span></label>
<div class="col-sm-4">
<input type="number" name="skm" class="form-control" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Date of Change<span style="color:red">*</span></label>
<div class="col-sm-4">
<input type="date" name="dateofchange" class="form-control" required>
</div>
<label class="col-sm-2 control-label">Engine Oil<span style="color:red">*</span></label>
<div class="col-sm-4">
<input type="number" step=".01" name="engineoil" class="form-control" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Coolant<span style="color:red">*</span></label>
<div class="col-sm-4">
<input type="number" step=".01" name="coolant" class="form-control" required>
</div>
<label class="col-sm-2 control-label">Brake Fluid<span style="color:red">*</span></label>
<div class="col-sm-4">
<input type="number" step=".01" name="brakefluid" class="form-control" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Battery<span style="color:red">*</span></label>
<div class="col-sm-4">
<input type="number" step=".01" name="battery" class="form-control" required>
</div>
<label class="col-sm-2 control-label">Tyre<span style="color:red">*</span></label>
<div class="col-sm-4">
<input type="number" step=".01" name="tyre" class="form-control" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Air Filter<span style="color:red">*</span></label>
<div class="col-sm-4">
<input type="number" step=".01" name="airfilter" class="form-control" required>
</div>
<label class="col-sm-2 control-label">Electrical<span style="color:red">*</span></label>
<div class="col-sm-4">
<input type="number" step=".01" name="electrical" class="form-control" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Wheel Alignment<span style="color:red">*</span></label>
<div class="col-sm-4">
<input type="number" step=".01" name="wheel" class="form-control" required>
</div>
<label class="col-sm-2 control-label">Diesel Filter<span style="color:red">*</span></label>
<div class="col-sm-4">
<input type="number" step=".01" name="dieselfilter" class="form-control" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Vehicle Body<span style="color:red">*</span></label>
<div class="col-sm-4">
<input type="number" step=".01" name="vehiclebody" class="form-control" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Others<span style="color:red">*</span></label>
<div class="col-sm-10">
<textarea class="form-control" rows="5" name="others" required></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Cost of Others<span style="color:red">*</span></label>
<div class="col-sm-4">
<input type="number" step=".01" name="costothers" class="form-control" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-2">
<button class="btn btn-primary" name="submit" type="submit">Send</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Loading Scripts -->
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap-select.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.bootstrap.min.js"></script>
<script src="js/Chart.min.js"></script>
<script src="js/fileinput.js"></script>
<script src="js/chartData.js"></script>
<script src="js/main.js"></script>
<script type="text/javascript">
$(document).ready(function () {
setTimeout(function() {
$('.succWrap').slideUp("slow");
}, 3000);
});
</script>
</body>
</html>
<?php } ?>