PDA

View Full Version : How to make foreign key linking in PHP/MYSQL?



devil_vin
10-10-2007, 05:07 PM
Hey..guys! I have INSERTstatement here which have two foreign keys that need to refer to other tables.How can I achieve it?



$sql = sprintf("INSERT INTO `reserve` (`reserve_datetime`, `seat_qty`, `ref_code`, `movie_id`, `member_id`) VALUES ('%s', '%s', '%s', '1', '1')", $date, $noOfSeat, $refCode);


movie_id and member_id are foreign keys that linked to movie and member tables respectively.Thanks for your help..

devil_vin
10-11-2007, 06:28 AM
if refer member_id like below,my insert statement can't work



$foreign1 = "SELECT member_id FROM member WHERE
email = \"" . $_SESSION['gmemberid'] . "\" ";

$sql = sprintf("INSERT INTO `reserve` (`reserve_datetime`, `seat_qty`, `ref_code`, `movie_id`, `member_id`) VALUES ('%s', '%s', '%s', '1', '$foreign1')",
$date, $noOfSeat, $refCode);
mysql_query($sql);