在我的sql数据库中插入外键值?

时间:2016-03-28 16:08:22

标签: php mysql

我想在表中插入外键值。我有两个故事员工(employee_id)和出勤率。这里employee_id是考勤表中的外键。 我尝试了很多,但没有插入值。 这是我的代码

if(isset($_POST['submit']))
{
$date   =    date('Y-m-d',strtotime($_POST['daily_date']));
$in     =    $_POST['daily_in'];
$l_out  =    $_POST['lunch_out'];
$l_in   =    $_POST['lunch_in'];
$out    =    $_POST['daily_out'];
$emp_remarks     =            $_POST['remarks'];
$sql = "INSERT INTO  attendance (atten_id,daily_date,daily_in,lunch_out,lunch_in,daily_out,remarks,employee_id)
VALUES('NULL','$date','$in','$l_out','$l_in','$out','$emp_remarks','".$_REQUEST['employee_id']."')";
   $res = mysql_query($sql);
        if ($res > 0) {
        echo "inserted";  
         }

如果我在代码下面运行

            if(isset($_POST['submit']))
        {  
            $date            =          $_POST['daily_date'];
            $in              =            $_POST['daily_in'];
            $l_out           =            $_POST['lunch_out'];
            $l_in            =            $_POST['lunch_in'];
            $out             =            $_POST['daily_out'];
            $emp_remarks     =            $_POST['remarks'];

        if(isset($_REQUEST['employee_id']))
    {
     echo "Employee Id" .$_REQUEST['employee_id'];
    } 

    else {
     echo "Smoething went wrong";
    }
            $sql = "INSERT INTO  attendance (atten_id,daily_date,daily_in,lunch_out,lunch_in,daily_out,remarks,employee_id)
    VALUES
    ('NULL','$date','$in','$l_out','$l_in','$out','$emp_remarks','".$_REQUEST['employee_id']."')";



its gives 
Smoething went wrong not inserted error

1 个答案:

答案 0 :(得分:0)

在插入之前尝试此操作,尝试此操作以检查值是否已通过。

isset($_REQUEST['employee_id'])
{ echo "Employee Id" .$_REQUEST['employee_id'];
} else {
 echo "Smoething went wrong";
}