1 Replies - 316 Views - Last Post: 07 April 2014 - 04:19 PM Rate Topic: -----

#1 ChrisNt  Icon User is offline

  • cute bug

Reputation: 212
  • View blog
  • Posts: 648
  • Joined: 31-July 13

Associate unique key with foreign key

Posted 07 April 2014 - 04:03 PM

How i can assosiate my unique key with the foreign key? I upload a video into the database and i want to connect it with another table which will have the location of video's picture.So when i upload a video i create a folder in which i save the thumbnail and then i insert the video to the database ,i want to connect the video_id with another table which will have the video_id and the location of the image..


if (isset($_FILES["myfile"])) {
    $ret = array();

    $error = $_FILES["myfile"]["error"];


    if (!is_array($_FILES["myfile"]["name"])) { //single file
        $fileName = $_FILES["myfile"]["name"];

        $ffmpeg = "C:\\ffmpeg\\bin\\ffmpeg";
        $userId = $_SESSION['user_id'];
        $videoFile = $_FILES["myfile"]["tmp_name"];


        $end = ".png";
        $name = $userId;
        $imageFile = $name . ".png";
        $size = "120x90";
        $getFromSecond = 10;
        $id = "id" . $userId;

        $cmd = "$ffmpeg -i $videoFile -an -ss  $getFromSecond -s $size $id/$imageFile";
        shell_exec($cmd);



        move_uploaded_file($_FILES["myfile"]["tmp_name"], "$output_dir/" . $fileName);

        $location = "$output_dir/" . $fileName;
        $thumbnail = "$id/$imageFile";


        //////////////////////////////////////// add db

        $query = "INSERT INTO video(name,location,user_id,thumbnail_loc) VALUES ('$fileName','$location','$userId','$thumbnail')";
      
        if (!mysqli_query($connection, $query)) {
            echo 'error';
        }
        



This post has been edited by ChrisNt: 07 April 2014 - 04:05 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Associate unique key with foreign key

#2 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 387
  • Posts: 1,409
  • Joined: 15-January 14

Re: Associate unique key with foreign key

Posted 07 April 2014 - 04:19 PM

You can use this to get the new automatic ID to use as the foreign key:

http://www.php.net/m...i.insert-id.php
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1