我有一个问题,我在 MYSQL 中创建了两个表,其中一个表是 bookticket,另一个表是客户表。
客户表 customer_id(pk)、全名、matric_id、ic_no、性别、地址、邮政编码、状态、hp_number、tel_number、用户名、密码、重复密码。
booktickect table ticket_id(pk) ,liner,direction,from,f_date,f_time,destination,t_date,t_time,total_price, customer_id(fk)
所以现在在我注册并以用户身份登录后,我如何创建一个 php 代码来输入 bookticket 数据,它将根据我在 bookticket 表中实现的 customer_id 外键自动分配给当前登录的用户。先感谢您。
很抱歉没有在我之前的帖子中提供我的 php 代码。我已经编辑了我的问题。:)
<?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!";
}
}
?>