title: How to save file path in database and show path in detail page
body: <p>I am busy with a small project where people can fill in a form which will save the values into a database. Now everything is working fine exept for file upload path. In my database I got three tables person, address and cv (with relations) see picture:</p>
  
  <p><img src="https://s24.postimg.org/r70frv8zp/2016_03_02_20_53_00_localhost_8080_localhost.png" alt="picture one"></p>
  
  <p>Now I want the path to be www.test.nl/directory/filename so I can make a button with the link so when you press the button it will download the file. How ever on my detail page as you can see it is showing the cv_id and not the path. My file upload is in a seperate file as is my person and address upload see below:</p>
  
  <p>address and person upload:</p>
  
  <pre><code>&lt;?php
  $servername = "localhost";
  $username = "root";
  $password = "usbw";
  $dbname = "persons";
  
  // CREATE A CONNECTION WITH THE DATABASE
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn-&gt;connect_error) {
  die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  // ADDRESS APPEND - PREPARE SQL STATEMENT AND BIND PARAMS
  // ADRES TOEVOEGEN - BEREID SQL STATEMENT EN BIND PARAMS
  $stmt = $conn-&gt;prepare("INSERT INTO address (address_street, address_housenumber, 
                                           address_zipcode, address_city, address_state)
                      VALUES (?, ?, ?, ?, ?)");
  $stmt-&gt;bind_param("sssss", $straat, $huisnummer, $postcode, $stad, $provincie);
  
  $straat = htmlspecialchars($_POST['straat']);
  $huisnummer = htmlspecialchars($_POST['huisnummer']);
  $postcode = htmlspecialchars($_POST['postcode']);
  $stad = htmlspecialchars($_POST['stad']);
  $provincie = htmlspecialchars($_POST['provincie']);
  
  // EXECUTE STATEMENT
  // STATEMENT UITVOEREN
  $result = $stmt-&gt;execute();    
  if ($result === FALSE) {
  die("Error: " . $stmt-&gt;error);
  }
  
  // CAPTURE LAST INSERTED address_id
  // PAK DE LAATST INGEVOERDE address_id
  $last_id = $conn-&gt;insert_id;
  
  // PERSON APPEND - PREPARE SQL STATEMENT AND BIND PARAMS
  // PERSOON TOEVOEGEN - BEREID SQL STATEMENT EN BIND PARAMS
  $stmt = $conn-&gt;prepare("INSERT INTO person (person_firstname, person_lastname, 
                                          person_email, person_phonenumber,
                                          person_cv, person_address)
                       VALUES (?, ?, ?, ?, ?, ?)");
   $stmt-&gt;bind_param("sssssi", $firstname, $lastname, $email, $telephone, $cv, $last_id);
  
  $firstname = htmlspecialchars($_POST['firstname']);
  $lastname = htmlspecialchars($_POST['lastname']);
  $email = htmlspecialchars($_POST['email']);
  $telephone = htmlspecialchars($_POST['telephone']);
  
  // EXECUTE STATEMENT
  // STATEMENT UITVOEREN
  $result = $stmt-&gt;execute();    
  if ($result === TRUE) {
  $URL="http://localhost:8080/Website/bedankt.php";  
  header ("Location: $URL");  
  } else {
      echo "Error: " . $stmt-&gt;error;
  }
  
  // CLOSE CONNECTION AND STATEMENT
  // SLUIT CONNECTIE EN STATEMENT
  $stmt-&gt;close();
  $conn-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>file upload.php</p>
  
  <pre><code> &lt;?php
   $servername = "localhost";
   $username = "root";
   $password = "usbw";
   $dbname = "persons";
  
  // CREATE A CONNECTION WITH THE DATABASE
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn-&gt;connect_error) {
  die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  if(isset($_POST['submit']))
  {
    $filetmp = $_FILES["cv"]["tmp_name"];
    $filename = $_FILES["cv"]["name"];
    $filetype = $_FILES["cv"]["type"];
    $filepath = "files/".$filename;
  
    move_uploaded_file($filetmp,$filepath);
  
    $sql = "INSERT INTO cv (cv_name,cv_path,cv_type) VALUES ('$filename','$filepath','$filetype')";
    $result = mysqli_query($conn, $sql);
  }
  $cv = $conn-&gt;insert_id;
  ?&gt;
  </code></pre>
  
  <p>My detail page:</p>
  
  <pre><code>&lt;?php
  $servername = "localhost";
  $username = "root";
  $password = "usbw";
  $dbname = "persons";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
  die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  $sql = "SELECT person_firstname, person_lastname, 
             person_email, person_phonenumber, person_cv,  
             address_street,address_housenumber, 
             address_city,address_state,address_zipcode 
      FROM person 
         inner join address on address.address_id = person.person_address";
  $result = $conn-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt; 0) {
  echo "&lt;table border=1&gt;
  &lt;tr&gt;
  &lt;th&gt;Voornaam&lt;/th&gt;
  &lt;th&gt;Achternaam&lt;/th&gt;
  &lt;th&gt;Straat&lt;/th&gt;
  &lt;th&gt;Huisnummer&lt;/th&gt;
  &lt;th&gt;Postcode&lt;/th&gt;
  &lt;th&gt;Stad&lt;/th&gt;
  &lt;th&gt;Provincie&lt;/th&gt;
  &lt;th&gt;Email&lt;/th&gt;
  &lt;th&gt;Mobiel&lt;/th&gt;
  &lt;th&gt;CV&lt;/th&gt;
  &lt;/tr&gt;";
  
  
  while($row = $result-&gt;fetch_assoc()) {
      echo "&lt;tr&gt;";
      echo "&lt;td&gt;" . $row["person_firstname"] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row["person_lastname"] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row["address_street"] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row["address_housenumber"] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row["address_zipcode"] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row["address_city"] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row["address_state"] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row["person_email"] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row["person_phonenumber"] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row["person_cv"] . "&lt;/td&gt;";
      echo "&lt;/tr&gt;";
  }
  } else {
  echo "Er is niks in het database gevonden";
  }
  $conn-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>I hope you guys can help me with this I am new to PHP so I am still learning this all. Note that everything is working well... exept the upload www.test.nl/directory/filename and saving this into my table cv_path... As showing the path (maybe as a button) in the detail page. If there is a way using almost the same statement as address to upload a file to cv than that would be great. But because this is working now (for so far) I keep my file upload and person and address upload seperated. And if it's possible to add a download button into my detail page under CV which will download the file that would be perfect.</p>