简体   繁体   English

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

[英]Insert foreign key value in my sql database?

I want to insert foreign key value in table.I have two tales employee(employee_id) and attendance.我想在表中插入外键值。我有两个故事员工(employee_id)和出勤。 Here employee_id is foreign key in attendance table.这里employee_id 是考勤表中的外键。 I try a lot but value is not inserted.我尝试了很多,但没有插入值。 Here is my code这是我的代码

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 I run below code then如果我运行下面的代码然后

            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

Before inserting try this , try this to check whether value was passed or not.在插入 try this 之前,try this 检查值是否被传递。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM