Advanced Search

Results 1 to 2 of 2

Thread: How to make foreign key linking in PHP/MYSQL?

  1. #1
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to make foreign key linking in PHP/MYSQL?

    Hey..guys! I have INSERTstatement here which have two foreign keys that need to refer to other tables.How can I achieve it?

    Code:
    $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..

  2. #2
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    if refer member_id like below,my insert statement can't work

    Code:
    $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);

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •