i am trying to add an entry into another table using:
function BeforeAdd(&$values)
{
// Parameters:
// $values - Array object.
// Each field on the Add form represented as 'Field name'-'Field value' pair
//********** Save new data in another table ************
global $conn,$strTableName;
$strSQLSave = "INSERT INTO _1ee0 (fname, lname, student_no, email) values (";
$strSQLSave .= $values["fname"].",";
$strSQLSave .= $values["lname"].",";
$strSQLSave .= $values["student_no"].",";
$strSQLSave .= $values["email"];
$strSQLSave .= ")";
db_exec($strSQLSave,$conn);
return true;
// return true if you like to proceed with adding new record
// return false in other case
}
when i enter any value for student_no
i am getting the following error:
Cannot add or update a child row: a foreign key constraint fails (`test/_1ee0`, CONSTRAINT `student_no` FOREIGN KEY (`student_no`) REFERENCES `_students` (`student_no`) ON DELETE CASCADE ON UPDATE CASCADE)
Why is that? any solution? my tables have parent-child relationships