我想这是一个简单的功能&我错过了某处的编码。寻求帮助。
我得到了用户的输入日期&添加/计算工作日。 php代码适用于&从数据库中检索输入时显示。但我想计算用户提供输入和输入的日子。通过提交按钮将其传递给数据库。
这是我的编码。请帮忙
<?php
include_once('confiq.php');
// Only process the form if $_POST isn't empty
if ( ! empty( $_POST ) ) {
// Connect to MySQL
$mysqli = new mysqli( 'localhost', 'root', '', 'fiber' );
// Check our connection
if ( $mysqli->connect_error ) {
die( 'Connect Error: ' . $mysqli->connect_errno . ': ' . $mysqli->connect_error );
}
// Insert our data
$sql = "INSERT INTO fiberexcel ( SiteID0, SiteName1, SiteAddress2, ProjectType3, ReqDate4, TargetDate5, Vendor6, ESRNo7, Contact8, Engineer9, AM10 )
VALUES ( '{$mysqli->real_escape_string($_POST['SiteID0'])}',
'{$mysqli->real_escape_string($_POST['SiteName1'])}' ,
'{$mysqli->real_escape_string($_POST['SiteAddress2'])}',
'{$mysqli->real_escape_string($_POST['ProjectType3'])}',
'{$mysqli->real_escape_string($_POST['ReqDate4'])}',
'{$mysqli->real_escape_string($_POST['TargetDate5'])}',
'{$mysqli->real_escape_string($_POST['Vendor6'])}',
'{$mysqli->real_escape_string($_POST['ESRNo7'])}',
'{$mysqli->real_escape_string($_POST['Contact8'])}',
'{$mysqli->real_escape_string($_POST['Engineer9'])}',
'{$mysqli->real_escape_string($_POST['AM10'])}')";
$insert = $mysqli->query($sql);
// Print response from MySQL
if ( $insert ) {
echo "!";
} else {
die("Error: {$mysqli->errno} : {$mysqli->error}");
}
// Close our connection
$mysqli->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Create Customer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/layout1.css" media="screen" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.css">
</head>
<body>
<div id="wrapper">
<div id="home"><a href="index.html"><img src="./img/home.png"></img></a>
</div>
<h2><u>CREATE CUSTOMER</u></h2>
<form action="Create.php" method="post">
<table border="0" align="left" cellspacing="30" height="5">
<tr><td><b>Site ID:</b></td> <td><input type="text" id="SiteID0" name="SiteID0" size="35" required="required"><br></td></tr>
<tr><td><b>Site Name:</b></td> <td><input type="text" id="SiteName1" name="SiteName1" size="35" required="required"><br></td></tr>
<tr><td><b>Site Address:</b></td> <td><input type="text" id="SiteAddress2" name="SiteAddress2" size="35" required="required"><br></td></tr>
<tr><td><b>Project Type:</b></td> <td><input type="text" id="ProjectType3" name="ProjectType3" size="35"><br></td></tr>
<tr><td><b>Requested Date:</b></td> <td><input type="date" id="ReqDate4" name="ReqDate4" size="35"><br></td></tr>
<tr><td><b>Target Completion Date</b></td>
<td><input type="date" id="TargetDate5"
<?php
$ReqDate4= date("Y-m-d"); //increment 75 days
$TargetDate5 = strtotime($ReqDate4."+ 75 weekday");
echo date("Y-m-d",$TargetDate5) . "\n";
echo "</td>";
$_POST['$TargetDate5 ']=$TargetDate5 ;
echo "</td>";
;?>
<br></td></tr>
<tr><td><b>Vendor:</b></td> <td><input type="text" id="Vendor6" name="Vendor6" size="35" required="required"><br></td></tr>
<tr><td><b>ESR No:</b></td> <td><input type="text" id="ESRNo7" name="ESRNo7" size="35" ><br></td></tr>
<tr><td><b>Contact Details:</b></td> <td><input type="text" id="Contact8" name="Contact8" size="35" ><br></td></tr>
<tr><td><b>Engineer:</b></td> <td><input type="text" id="Engineer9" name="Engineer9" size="35" required="required"><br></td></tr>
<tr><td><b>Account Manager:</b></td> <td><input type="text" id="AM10" name="AM10" size="35" ><br></td></tr>
<tr>
<td></td><td><input type="submit" value="Submit" name="action" /></td>
<td><input type ="submit" value="Clear" onclick="reset();"></td>
</tr>
</form>
</table>
</div>
</body>
</html>
答案 0 :(得分:0)
<script>
function emergencyleavecomp(){
document.getElementById("startDate").value = "";
document.getElementById("endDate").value = "";
document.getElementById("count").value = "";
document.getElementById("remain_leave").value = "";
document.getElementById("calculate").value = "";
document.getElementById("Used_Leave").value = "";
document.getElementById("sickleave").checked = false;
// document.getElementById("emergencyleave").checked = false;
document.getElementById("paternityleave").checked = false;
document.getElementById("maternityleave").checked = false;
document.getElementById("compasionateleave").checked = false;
document.getElementById("vacationleave").checked = false;
var emerleave = document.getElementById("emergencyleave");
//
// document.getElementById("vacationleave").checked = false;
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
//January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
// document.write(today);
var checkcategory = (document.getElementById("checkcategory").value);
// var vacay = document.getElementById("vacationleave");
//
if(emerleave.checked){
var emeval = document.getElementById("foremergencyleave").value;
document.getElementById("Used_Leave").value = emeval;
if(checkcategory == "Local"){
$('#startDate').on('change',function(){
var probDate=new Date(document.getElementById("forcomputeleave").value);
var nowDate= new Date(document.getElementById("startDate").value);
var timeDiff=Math.abs(probDate.getTime()-nowDate.getTime());
var diffDays=Math.ceil(timeDiff/(1000*3600*24));
// document.getElementById("count").innerHTML = diffDays;
var calc = Math.round((diffDays * 0.0416666666666667)*100)/100;
document.getElementById("calculate").value = calc;
var remain = Math.round((calc - document.getElementById("Used_Leave").value)*100)/100;
document.getElementById("remain_leave").value = remain;
});
}
else{
$('#startDate').on('change',function(){
var probDate=new Date(document.getElementById("forcomputeleave").value);
var nowDate= new Date(document.getElementById("startDate").value);
var timeDiff=Math.abs(probDate.getTime()-nowDate.getTime());
var diffDays=Math.ceil(timeDiff/(1000*3600*24));
// document.getElementById("count").innerHTML = diffDays;
var calc = Math.round((diffDays * 0.0833333333333333)*100)/100;
document.getElementById("calculate").value = calc;
var remain = Math.round((calc - document.getElementById("Used_Leave").value)*100)/100;
document.getElementById("remain_leave").value = remain;
});
}
}
}
</script>
您可以将此代码编辑为您想要执行的操作。这计算从日期到另一个日期。如果这就是你的要求。
答案 1 :(得分:0)
您在&#39; 目标完成日期&#39;中缺少 name =&#34; TargetDate5&#34; 字段因此它不会发布在$ _POST数组中。
此外,以下值不会从表单发布,但会显示在您的查询中。
$_POST['ESRNo7']
$_POST['Contact8']
$_POST['Engineer9']
$_POST['AM10']