我有一个名为'programs'的表,其中'Program_name'是主键。还有另一个名为'po_attainment'的表,其中我将'Program_name'定义为外键。我创建了一个页面,我输入Program_name和session,并存储在名为'programs'的表中。我做了另一个页面,我计算了一些po(程序结果)的平均值,并将其存储在另一个名为'po_avg'的表中。这里只有两个表'program'和'po_attainment'有关。我的代码如下:
<?php
@include("connection.php");
error_reporting(0);
$year=$_POST["year"];
$avg=$_POST["Avg"];
$avg1=$_POST["Avg1"];
$program=$_POST["Program_name"];
if($_POST["submit"])
{
$sql="select * from po_avg";
$rData=mysql_query($sql);
$res=mysql_fetch_array($rData);
$sql="insert into po_avg values('','$avg','$avg1','$year')";
mysql_query($sql);
}
if($avg>=80){
$sql="select * from po_attainment";
$rData=mysql_query($sql);
$res=mysql_fetch_array($rData);
$sql="insert into po_attainment values('','PO1','H','$program')";
mysql_query($sql);
}
else if($avg>=60) {
$sql="select * from po_attainment";
$rData=mysql_query($sql);
$res=mysql_fetch_array($rData);
$sql="insert into po_attainment values('','PO1','M','$program')";
mysql_query($sql);
}
else if($avg>=40)
{
$sql="select * from po_attainment";
$rData=mysql_query($sql);
$res=mysql_fetch_array($rData);
$sql="insert into po_attainment values('','PO1','L','$program')";
mysql_query($sql);
}
if($avg1>=80){
$sql="select * from po_attainment";
$rData=mysql_query($sql);
$res=mysql_fetch_array($rData);
$sql="insert into po_attainment
values('','PO2','H','$program')";
mysql_query($sql);
}
else if($avg1>=60)
{
$sql="select * from po_attainment";
$rData=mysql_query($sql);
$res=mysql_fetch_array($rData);
$sql="insert into po_attainment
values('','PO2','M','$program')";
mysql_query($sql);
}
else if($avg1>=40)
{
$sql="select * from po_attainment";
$rData=mysql_query($sql);
$res=mysql_fetch_array($rData);
$sql="insert into po_attainment values('','PO2','L','$program')";
mysql_query($sql);
}
?>
我无法在'po_attainment'表中插入'Program_name'。如何从关系表'programs'中的'po_attainment'表中插入'Program_name'。
programs table- p_id(pk),Program_name(pk),year
po_attainment table- att_id(pk),po_name,att_level,Program_name(fk)
po_avg table- po_id(pk),avg,avg1,year.