我遇到了问题,我在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