我遇到了問題,我在MYSQL中創建了兩個表,其中一個表是bookticket,另一個表是客戶表。將數據插入通過外鍵連接到另一個表的數據
客戶表 CUSTOMER_ID(PK),全名,matric_id,ic_no,性別,地址,郵編,國家,hp_number,tel_number,用戶名,密碼,repeatpassword。
booktickect表 TICKET_ID(PK),襯板,方向,從,f_date,f_time,目的地,t_date,t_time,TOTAL_PRICE,CUSTOMER_ID(FK)
所以,現在我已經註冊之後和登錄作爲用戶,我如何創建一個php代碼來輸入bookticket數據,根據我在我的bookticket表中實現的customer_id外鍵,它將自動分配給當前登錄的用戶。敬請提前感謝。
對不起,我沒有提供我的php代碼在我以前post.I編輯了我的問題。 :)
<?php
echo "<h1>Booking</h1>";
$submit = $_POST['submit'];
//ticket booking form data
$liner = strip_tags($_POST['liner']);
$direction = strip_tags($_POST['direction']);
$from = strip_tags($_POST['from']);
$f_date = strip_tags($_POST['f_date']);
$f_time = strip_tags($_POST['f_time']);
$destination = strip_tags($_POST['destination']);
$t_date = strip_tags($_POST['t_date']);
$t_time = strip_tags($_POST['t_time']);
$total_price = strip_tags($_POST['txttotal']);
if ($submit)
{
//check the direction selected by user
if ($direction == "return")
{
//check for existance
if($liner && $direction && $from && $f_date && $f_time && $destination && $t_date && $t_time && $total_price)
{
$connect = mysql_connect("localhost" ,"cc11205","11205");
mysql_select_db("cc11205");
$queryreg = mysql_query("
INSERT INTO bookticket VALUES ('','$liner','$direction','$from','$f_date','$f_time','$destination','$t_date','$t_time','$total_price','');
");
die("Your booking details has been succesfully inserted into the database.Please <a href='customer.php'>Click here</a> to go to the main page to view your booking");
}
else
echo "Please fill in <b>all</b> fields!";
}
else if ($direction == "oneway")
{
if($liner && $direction && $from && $f_date && $f_time && $destination && $total_price )
{
$connect = mysql_connect("localhost" ,"cc11205","11205");
mysql_select_db("cc11205");
$queryreg = mysql_query("
INSERT INTO bookticket VALUES ('','$liner','$direction','$from','$f_date','$f_time','$destination','','','$total_price','');
");
die("Your booking details has been succesfully inserted into the database.Please <a href='customer.php'>Click here</a> to go to the main page to view your booking");
}
else
echo "Please fill in <b>all</b> fields!";
}
}
?>
歡迎來到StackOverlow!這是一個非常廣泛的問題。你需要把它縮小到你不明白或者有問題的地方。如果你只是希望有人爲你寫代碼StackOverflow是錯誤的地方問,你可以嘗試自由職業者的網站。 – peterm 2013-05-11 02:45:45
Mr.peterm我很抱歉。我重新修正了這個問題。如果再次出現任何錯誤,請告訴我。謝謝。 – 2013-05-11 03:16:00