如何两次插入同一个表?

时间:2013-01-14 00:41:17

标签: php mysql forms if-statement insert

我正在创建一个预订系统(机场出租车公司),该系统最初会创建一个存储客户联系人的预订系统。计费详细信息等,然后使用ID将旅程信息发布到另一个表中,如果包含返回详细信息,则在返回旅程的同一个JOBS表中创建另一个记录。我正在使用IF语句检查是否已提交退货详情。但是,它只会插入第一个旅程,而不是返回。见下面的代码。

有什么想法吗?

我也很欣赏我很有可能以一种奇怪的方式来实现我的结果,所以任何批评和指示也都受到欢迎。

由于

<?php


$customer_title          =  $_POST['customer_title'];
$customer_first_name     =  $_POST['customer_first_name'];
$customer_last_name      =  $_POST['customer_last_name'];
$billing_address         =  $_POST['billing_address'];
$customer_tel            =  $_POST['customer_tel'];
$customer_mobile         =  $_POST['customer_mobile'];
$customer_email          =  $_POST['customer_email'];
$passengers              =  $_POST['passengers'];
$cases                   =  $_POST['cases'];
$return_flight_number    =  $_POST['return_flight_number'];
$price                   =  $_POST['price'];
$pickup_date             =  $_POST['pickup_date'];
$pickup_time             =  $_POST['pickup_time'];
$pickup_address          =  $_POST['pickup_address'];
$pickup_destination      =  $_POST['pickup_destination'];
$return_date             =  $_POST['return_date'];
$return_time             =  $_POST['return_time'];
$return_pickup           =  $_POST['return_pickup'];
$return_destination      =  $_POST['return_destination'];
$booking_notes           =  $_POST['booking_notes'];

$booking_status          =  Confirmed;
$account_number          =  9999;
$authorised              =  N;


$booking_date            = 0;
$null_date               = '0000-00-00'; 


include('../assets/db_connection.php');

mysql_select_db("airporthopper");

mysql_query("INSERT INTO bookings(customer_name, billing_address, account_number, contact_tel, contact_mob, contact_email,
            party_pax, party_cases, booking_notes, price, booking_agent, booking_date, booking_status, authorised)
VALUES('$customer_title $customer_first_name $customer_last_name', '$billing_address', $account_number, '$customer_tel', '$customer_mobile', '$customer_email', '$passengers', '$cases', '$booking_notes', '$price', 'Danny Green', '$booking_date',
    '$booking_status', '$authorised'   )");



$booking_ref = mysql_insert_id();

mysql_query("INSERT INTO jobs(booking_ref, pickup_date, pickup_time, pickup_address, destination_address, scheduled)VALUES('$booking_ref', '$pickup_date', '$pickup_time', '$pickup_address', '$pickup_destination', 'N')");

if ($return_date != $null_date) {
mysql_query("INSERT INTO jobs(booking_ref, pickup_date, pickup_time, pickup_address, destination_address, return, scheduled)VALUES('$booking_ref', '$return_date', '$return_time', '$return_pickup', '$return_destination', 'Y' , 'N')");
 }




?> 

1 个答案:

答案 0 :(得分:0)

而不是“if($ return_date!= $ null_date){”,请使用:

if (strtotime($return_date) > 0) {

此外,我希望'jobs'表中的'booking_ref'列没有与之关联的唯一索引