我有2张桌子。第一个是客户,第二个是发票,两个都有一行“客户ID”。通过网络表单添加新发票时,我该怎么做才能获取客户的“客户ID”,并在提交表单时将其与发票中的“客户ID”一起放入新信息中?
这是我的index.php的代码
?php
include 'DBConfig.php';
//Insert or Update contact information
if(isset($_POST['action_type']))
{
if ($_POST['action_type'] == 'add' or $_POST['action_type'] == 'edit')
{
//Sanitize the data and assign to variables
$invum = mysqli_real_escape_string($link, strip_tags($_POST['invnum']));
$cost = mysqli_real_escape_string($link, strip_tags($_POST['cost']));
if ($_POST['action_type'] == 'add')
{
$sql = "insert into invoice set
cost = '$cost'";
}else{
$sql = "update invoice set
cost = '$cost',
where invnum = $invnum";
}
if (!mysqli_query($link, $sql))
{
echo 'Error Saving Data. ' . mysqli_error($link);
exit();
}
}
header('Location: invoicelist.php');
exit();
}
//End Insert or Update contact information
//Start of edit contact read
$gresult = ''; //declare global variable
if(isset($_POST["action"]) and $_POST["action"]=="edit"){
$id = (isset($_POST["ci"])? $_POST["ci"] : '');
$sql = "select invnum, cost from invoice
where invnum = $id";
$result = mysqli_query($link, $sql);
if(!$result)
{
echo mysqli_error($link);
exit();
}
$gresult = mysqli_fetch_array($result);
include 'invoiceupdate.php';
exit();
}
//end of edit contact read