在1列中插入多值

时间:2013-09-13 13:44:21

标签: php

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

$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"); 

1 个答案:

答案 0 :(得分: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>';
}