-1
我想在表中插入外鍵值。我有兩個故事employee(employee_id)和考勤。這裏的employee_id是出席表中的外鍵。 我嘗試了很多,但沒有插入值。 這裏是我的代碼在我的sql數據庫中插入外鍵值?
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
根據您的代碼,「Smoething出錯了」意味着'employee_id'值不在'$ _REQUEST'集合中。這與您的數據庫交互無關。如果該值沒有被髮送到這個代碼,那麼這個代碼就不能使用它。 – David
我該如何解決這個問題? –
通過在試圖將'employee_id'插入數據庫時向頁面發佈信息。 – David