在php

时间:2015-06-06 21:20:32

标签: php

我正在尝试使用外键连接到表.. Cust_ID是主键,而account_id是外键。 但是不知道该怎么做..请帮助我。

<?php include("conn.php"); ?>
<?php
if((isset($_POST['insert'])) && ($_POST['insert']=='form3'))
{
$Customer_Name=$_POST['customerName'];
$Account_Type=$_POST['accountType'];
//$Account_No=$_POST['accountNo'];
$Cheque_Book_No=$_POST['chkBookNo'];
$Balance=$_POST['balance'];
$insertQuery="INSERT INTO account(account_type) VALUES('$Account_Type')";
$Insert=mysql_query($insertQuery);
$insertQuery2="INSERT INTO customer(Cust_Name,account_id,Balance,ckbook_No) VALUES('$Customer_Name','$_POST[account_id]','$Balance','$Cheque_Book_No')";
$Insert=mysql_query($insertQuery2);
header("location:account.php?insertion=done");
exit(1);
}
?>

1 个答案:

答案 0 :(得分:0)

如果您只想重新使用account_id中生成的INSERT密钥进入account表,您可以

$id = mysql_insert_id();

INSERT INTO account ...语句之后,请参阅此处:How do I get the last inserted ID of a MySQL table in PHP?