我想了解兩個日期之間有多少天的代碼波紋管是我所說的一個例子,但它不工作所有我在數據庫中得到的是0計算日期之間的天數
<?php
$hotel_name = $_POST['hotelName'];
$room_type = $_POST['roomType'];
//date From value
$dayfrom = $_POST['dayfrom'];
$monthfrom = $_POST['monthfrom'];
$yearfrom = $_POST['yearfrom'];
//date To value
$dayto = $_POST['dayto'];
$monthto = $_POST['monthto'];
$yearto = $_POST['yearto'];
$arivDate = sprintf('%04d-%02d-%02d', $yearfrom, $monthfrom, $dayfrom);
$depDate = sprintf('%04d-%02d-%02d', $yearto, $monthto, $dayto);
$child = $_POST['child'];
$adult = $_POST['adult'];
$days = $arivDate - $depDate;
//$sortedfromdate = strtotime($arivDate);
//$sortedtodate = strtotime($depDate);
$query = "INSERT INTO tempbooking(book_date, Ariv_date, dep_date, hotel_name
)VALUES(
CURDATE(), '{$arivDate}', '{$depDate}', '{$hotel_name}')";
if(mysql_query($query,$connection)){
$booking_id = mysql_insert_id();
}else{
die("The Booking was not successful". mysql_error());
}
$queryres="INSERT INTO ro_reservation(booking_id, children, adult, room_type, number_days
)VALUES(
{$booking_id}, {$child}, {$adult}, '{$room_type}',{$days})";
if(mysql_query($queryres,$connection)){
header("Location:index.php");
//echo"<a href=\"index.php\"> Reservation Inserted</a>";
}else{
echo "Nothing was inserted in to the ro_reservation";
}
?>
[SQL Injection](http://en.wikipedia.org/wiki/SQL_injection)alert:[防止SQL注入的最佳方法](http://stackoverflow.com/questions/60174/)最好的方式對防止-SQL注入式的PHP)。 – PeeHaa 2012-08-15 18:17:36
您正在減去字符串,而不是日期/時間值。 – 2012-08-15 18:35:26