两个问题:
当我点击“提交”时,输入文本框必须保存到数据库:
<?php
session_start();
if (!$_SESSION['uname']) {
header("Location:login.php");
}
?>
<html><head><title>Attendance sheet</title>
<link rel="stylesheet" href="att_style.css" type="text/css" >
<script src="datetimepicker.js"> </script>
<script type="text/javascript">
function IsNumber(strFieldValue, size, strAlert)
{
for ( var i=0; i < size; i++)
{
if(strFieldValue.charAt(i)!="" )
{
if( strFieldValue.charAt(i) < "0" || strFieldValue.charAt(i) > "9")
{
if(strAlert != "")alert(strAlert)
return false;
}
}
}
return true;
}
function IsValidTime(timeStr) {
var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
var matchArray = timeStr.match(timePat);
if (matchArray == null) {
alert("Time is not in a valid format.");
return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];
if (second=="") { second = null; }
if (ampm=="") { ampm = null }
if (hour < 0 || hour > 23) {
alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
return false;
}
if (hour <= 12 && ampm == null) {
if (confirm("Please indicate which time format you are using. OK = Standard Time, CANCEL = Military Time")) {
alert("You must specify AM or PM.");
return false;
}
}
if (hour > 12 && ampm != null) {
alert("You can't specify AM or PM for military time.");
return false;
}
if (minute<0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Second must be between 0 and 59.");
return false;
}
return false;
}
</script>
</head>
<body>
<form name="timeform" method="post" action="" >
<label for="range_start">Start range:</label> <input name="from" id="frm_date" type="text" >
<a href="javascript:NewCal('frm_date','ddmmyyyy')"><img src="cal.gif" alt="pick a date"></a>
<label for="range_end">End range:</label> <input name="to" id="dpk" type="text" >
<a href="javascript:NewCal('dpk','ddmmyyyy')"><img src="cal.gif" alt="pick a date"></a>
<input name="date_but" type="submit" value="Go">
<a style="float:right" href="logout.php">Logout</a>
<br/><br/>
<?php
if (isset($_REQUEST['date_but'])) {
$fromDate = $_REQUEST['from'];
$toDate = $_REQUEST['to'];
$dateMonthYearArr = array();
$fromDateTS = strtotime($fromDate);
$toDateTS = strtotime($toDate);
for ($currentDateTS = $fromDateTS; $currentDateTS <= $toDateTS; $currentDateTS += (60 * 60 * 24)) {
$currentDateStr = date("d-M-Y",$currentDateTS);
$dateMonthYearArr[] = $currentDateStr;
}
echo "No of days: " . count($dateMonthYearArr);
?>
<table border="1" cellspacing="0" cellpadding="5" align="center">
<tr>
<th scope="row">DATE</th>
<div class="dat_row">
<td><?php print_r($dateMonthYearArr[0]); ?></td>
<td><?php echo $dateMonthYearArr[1]; ?></td>
<td><?php echo $dateMonthYearArr[2]; ?></td>
<td><?php echo $dateMonthYearArr[3]; ?></td>
</div>
</tr>
<tr>
<th scope="row">IN</th>
<td><input name="time" type="text" ></td>
<td><input name="r2_in" type="text" ></td>
<td><input name="r2_in" type="text" ></td>
</tr>
<tr>
<th scope="row">OUT</th>
<td><input name="time" type="text"></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th scope="row">Leave</th>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table><br/><br/>
<input name="submit" type="submit" onClick="IsValidTime(document.timeform.time.value);" value="Submit">
<?php
} ?>
</form>
</body>
</html>
答案 0 :(得分:0)
希望这有帮助
function GetDays($sStartDate, $sEndDate){
// Firstly, format the provided dates.
// This function works best with YYYY-MM-DD
// but other date formats will work thanks
// to strtotime().
$sStartDate = gmdate("Y-m-d", strtotime($sStartDate));
$sEndDate = gmdate("Y-m-d", strtotime($sEndDate));
// Start the variable off with the start date
$aDays[] = $sStartDate;
// Set a 'temp' variable, sCurrentDate, with
// the start date - before beginning the loop
$sCurrentDate = $sStartDate;
// While the current date is less than the end date
while($sCurrentDate < $sEndDate){
// Add a day to the current date
$sCurrentDate = gmdate("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate)));
// Add this new day to the aDays array
$aDays[] = $sCurrentDate;
}
// Once the loop has finished, return the
// array of days.
return $aDays;
}