-1

我想插入数据库 2 值,当前选择的时间然后计算的时间。所以基本上,像这样。“7:00AM - 10:00AM”这是我当前的代码。它将空白插入数据库。

$date = new DateTime($res_dur);
$date->add(new DateInterval('PT3H'));
$date->format('H:i:s');
$ndate = $_POST[$res_dur][$date];

$query = "INSERT INTO tbl_reservation(
            res_no,cust_id,pack_type,plan_id,res_date,res_dur,
            res_venue,pack_choice,date_app,add_ons,res_comm) 
        VALUES
        ('','{$cust_id}','{$pack_type}','{$plan_id}','{$res_date}','{$ndate}',
            '{$res_venue}','{$pack_choice}',CURDATE(),'','')";

$result_set = mysql_query($query);


if ($result_set) {
    echo "<script language=javascript>alert('You have been successfully registered!')</script>";
    header("Location:home.php"); 
4

1 回答 1

0

添加一些调试代码以找出问题所在。

$date = new DateTime($res_dur);
$date->add(new DateInterval('PT3H'));
$date->format('H:i:s');
$ndate = $_POST[$res_dur][$date];

print_r( $_POST );
echo '<br>ndate = ' . $ndate . '<br>';

$query = "INSERT INTO tbl_reservation(
            res_no,cust_id,pack_type,plan_id,res_date,res_dur,
            res_venue,pack_choice,date_app,add_ons,res_comm) 
        VALUES
        ('','{$cust_id}','{$pack_type}','{$plan_id}','{$res_date}','{$ndate}',
            '{$res_venue}','{$pack_choice}',CURDATE(),'','')";

echo 'query = ' . $query . '<br>';


$result_set = mysql_query($query);


if ($result_set) {
    echo "<script language=javascript>alert('You have been successfully registered!')</script>";
    header("Location:home.php"); 
} else {
    echo 'Query failed - ' . mysql_errno() . ": " . mysql_error() . '<br>';
}
于 2013-09-13T14:16:28.917 回答