将值插入mysql表[重复]

This question already has an answer here:

Im having issues inserting a value which is a foreign key to another table.

I have two tables one is users and another one is paycheck. This is my paycheck table which has empId which is a foreign key to another table called users

$query = "INSERT INTO paycheck(payCheckId, jobId, payRate,
            jobLocation, hoursWorked, startPeriod, endPeriod, empId)
          VALUES('', '$pay_rate', '$job_location', '$hours',
            '$start', '$end', 'DONT KNOW WHAT TO PUT HERE ')";
$result = mysqli_query($db, $query); //we make the query

I am not sure what value to put into empId, all the values are coming from a textbox.

</div>

this the way to create a foreign key represented table

CREATE TABLE `ffxi_characterJob` (
`serverID` int(11) NOT NULL,
`userid` int(10)unsigned NOT NULL,
`characterName` varchar(255) NOT NULL,
`jobAbbr` char(4) NOT NULL,
`jobLevel` int(11) default '0',
PRIMARY KEY (`serverID`,`userid`,`characterName`,`jobAbbr`),
INDEX (`jobAbbr`),
CONSTRAINT FOREIGN KEY (`serverID`,`userid`,`characterName`) REFERENCES `ffxi_characters` (`serverID`,`userid`,`characterName`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT FOREIGN KEY (`jobAbbr`) REFERENCES `ffxi_jobType` (`jobAbbr`) ON DELETE CASCADE ON UPDATE CASCADE
) TYPE=InnoDB;

for if you created like this, then it automatically delete or update when you change the values in first(primary) table , to insert you need put the value that matches the column value of the first table


emp_id name value
  1    aaa   24
  2    bbb   23
  3    ccc   25
  4    ddd   27

pur_id emp_id amount
 000      1    500
 001      2    100
 002      1     50

in this second table emp_id is a foreign key ref with first table emp_id, so you need match value from first table

$query = "INSERT INTO paycheck(payCheckId,jobId,payRate,jobLocation,hoursWorked,startPeriod,endPeriod, empid)
VALUES('','$pay_rate','$job_location','$hours','$start','$end', 'value that you want t0 match from first table')";