2 つの日付を比較していますFrom_date
&To_date
データベース テーブルの行。
ロジックは次のとおりです。 ユーザーがこれら 2 つの日付 (テキストボックスから受け取った日付) の間に既に予算を設定している場合は、エラー メッセージを返しますBudget already set for this from-date & to-date
。
簡単にするために、日付をUnixタイムスタンプに変換しています。
以下のコードを試しましたが、結果が得られません。それはいつも私に間違ったメッセージを表示します Budget already set for this from-date & to-date
<?php if (isset($_POST['submit']))
{
include '../../../include/connection.php';
$frmdate= $_POST['frmdate'] ;
$todate=$_POST['todate'] ;
$fromTimestamp = strtotime( $frmdate );
$toTimestamp = strtotime( $todate );
function check_function($fromTimestamp,$toTimestamp)//function for checking the two dates which are rrecieved from the database table
{
$sid=$_SESSION['id'];
$result12=mysql_query("SELECT * FROM budget where creater_id = '$sid'");
while($test12 = mysql_fetch_array($result12))
{
$from_date = strtotime($test12['from_date']);//getting all the FROM-Dates_column
$to_date = strtotime($test12['to_date']);//getting all the TO-Dates_column
if((($fromTimestamp >= $from_date) && ($fromTimestamp <= $to_date)) || (($toTimestamp >= $from_date) && ($toTimestamp <= $to_date)))
{
return TRUE;
break;
}
return FALSE;
}
}
if(check_function($fromTimestamp,$toTimestamp))//Returns TRUE
{
mysql_query("INSERT INTO `budget` (heads_id,amount,from_date,to_date,creater_id,created_date,updater_id,updated_date) VALUES ('$headsid','$amount','$frmdate','$todate',$uid,NOW(),$uid,NOW())");
}
else
{
echo 'Budget already set for this from-date & to-date'; //
}
} ?>