title: PHP: After uploading a picture it won't load and there's a loophole
body: <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Filmovi&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;form action="unos.php" method="POST" enctype="multipart/form-data"&gt;
      &lt;table border = "1"&gt;
      &lt;tr&gt;
      &lt;td&gt;Naslov:&lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="naslov" value="" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
      &lt;td&gt;Žanr:&lt;/td&gt;
      &lt;td&gt;
      &lt;?php
  
      $conn = new mysqli('localhost', 'root', '', 'kolekcija');
      $result = $conn-&gt;query("SELECT id, naziv FROM zanr");
  
      echo "&lt;select name = 'id'&gt;";
      while($row = $result-&gt;fetch_assoc())
      {
          unset($id, $name);
          $id = $row['id'];
          $name = $row['naziv'];
          echo '&lt;option value = "' . $id . '"&gt;'.$name.'&lt;/option&gt;';
      }
  
      echo "&lt;/select&gt;";
  
      ?&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
      &lt;td&gt;Godina:&lt;/td&gt;
      &lt;td&gt;
      &lt;select name = "godina"&gt;
      &lt;?php
  
      for($i = 1900; $i &lt;= 2020; $i++)
      {
          echo "&lt;option value = " .$i . "&gt;" .$i . "&lt;/option&gt;";
      }
  
      ?&gt;
      &lt;option name = "godina"&gt;&lt;/option&gt;
      &lt;/select&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
      &lt;td&gt;Trajanje:&lt;/td&gt;
      &lt;td&gt;&lt;input type="integer" name="trajanje" value="" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
      &lt;td&gt;Slika:&lt;/td&gt;
      &lt;td&gt;&lt;input type="file" name="image" /&gt;
      &lt;input type = "hidden" name = "size" value = "1000000000" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
      &lt;td&gt;Gumb:&lt;/td&gt;
      &lt;td&gt;&lt;input type="submit" name="submit" value="Unos" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
          &lt;/table&gt;
      &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;?php
  
  $link = mysqli_connect("localhost", "root", "") or die 
  (mysqli_connect_errno());
  mysqli_select_db($link, "kolekcija") or die ("Nemoguće se spojiti na 
  bazu!".mysqli_connect_errno());
  
  if(isset($_POST['submit']))
  {
      $filename = $_FILES["image"]["name"];
      $filepath = "/unos.php:116".$filename;
      $naslov=$_POST['naslov'];
      $trajanje = $_POST['trajanje'];
      $zanr = $_POST['id'];
      $godina = $_POST['godina'];
      move_uploaded_file($filename, $filepath);
  
          $sql = "INSERT INTO filmovi (id, naziv_filma, trajanje, slika, 
  id_zanr, godina)
                  VALUES('null', '{$naslov}', '{$trajanje}' ,'{$filepath}', 
  '{$zanr}', '{$godina}');";
       $result = mysqli_query($link, $sql) or die("Error in Query insert: " . 
  mysqli_connect_errno());
  
      }
  
  $msg = "";
  
  $sql = "SELECT id, slika, naziv_filma, godina, trajanje FROM filmovi";
  $myData = mysqli_query($link, $sql); 
  echo "&lt;table border = '1'&gt;
  &lt;tr&gt;
  &lt;th&gt;Slika&lt;/th&gt;&lt;th&gt;Naziv filma&lt;/th&gt;&lt;th&gt;Godina&lt;/th&gt;&lt;th&gt;Trajanje&lt;/th&gt;
  &lt;th&gt;Akcija&lt;/th&gt;&lt;/tr&gt;";
  while($record = mysqli_fetch_array($myData)) 
      {
      echo "&lt;form action = 'unos.php' method = 'post' enctype='multipart/form-
  data'&gt;";
      echo "&lt;tr&gt;";
      echo "&lt;td&gt;" . $msg.= '&lt;img 
  src="data:image/jpeg;base64,'.base64_encode($record['slika']) .'"/&gt;' . "
  &lt;/td&gt;";
      echo "&lt;td&gt;" . $record['naziv_filma'] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $record['godina'] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $record['trajanje'] . "&lt;/td&gt;";
      echo '&lt;td&gt;[&lt;a href="unos.php?film='.$record[0].'"&gt;obriši&lt;/a&gt;]&lt;/td&gt;';
  
      if(isset($_GET['film']))
      {
          $id = ($_GET['film']);
  
          $sql_delete = "DELETE FROM filmovi WHERE id = {$id}";
  
          mysqli_query($link, $sql_delete);
  
          break;
      }
  
  
      echo "&lt;/tr&gt;";
      echo "&lt;/form&gt;";
      }
  
  
  
  
  echo "&lt;/table&gt;";
  
  ?&gt;
  </code></pre>
  
  <p>Okay, this is my code, I have a programming course and this was the 
  assigment. The idea was to make a form where you can put info about the movie, name, genre, year it was made and upload a picture. Everythign works and it's done but the only problem is that after uploading a picture (directly in the mysql database, I don't have a code where the picture is stored at the local disk), it won't load in the browser and after refreshing the browser the picture uploads itself again. It seems I have a loop somwhere but I can't figure out where 'cause I've been doing it and delaying the code for months as I'm stuck. Can someone help, please? Thank you very much in advance for all help!</p>