title: Image update php mysql
body: <p>I have a problem with updating images. Sending images to the server and insert new records runs without a problem but have not edited when editing photos, and data to the database are thrown only texts and records not responsible for the pictures.
  Thank you in advance for your help</p>
  
  <p><strong>Form</strong></p>
  
  <pre><code>&lt;?php
  //1. polaczenie z baza danych
  //polaczenie z baza danych + ustawienie kodowania na utf8
  $dbhost = "localhost";
  $dbuser = "root";
  $dbpass = "3edcvfr4";
  $dbname = "dw_bookstore";
  $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
  
  //sprawdzenie polaczenia
  if (mysqli_connect_errno()) {
      printf("Connect failed: %s\n", mysqli_connect_error());
      exit();
  }
  
  //zmaiana znako na utf8
  if (!mysqli_set_charset($connection, "utf8")) {
      printf("Error loading character set utf8: %s\n", mysqli_error($connection));
  } else {
      printf("Kodowanie ustawione na: %s\n", mysqli_character_set_name($connection));
  }
  ?&gt;
  
  &lt;?php
      // get ID
      @$id = $_GET['id'];
  
      @$query  = "SELECT * FROM photographs WHERE id = '$id' ";
      //pokazuje co zostalo zmienione
      echo $query;
  
      $result = mysqli_query($connection, $query);
      if (!$result) {
          die("zapytanie sie nie powiodlo");
      }
      $row = mysqli_fetch_array($result);
  
  ?&gt;
  
  
  &lt;?php
  //if (!id) {
  //  redirect_to("costam.php");
  //  }
  ?&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Update Form&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
          &lt;form action="database_update_action.php" method="post" enctype="multipart/form-data" name="form1" target="_blank"&gt;
        &lt;table border="0" cellspacing="2" cellpadding="2"&gt;
          &lt;tr&gt;
            &lt;td&gt;ID:&lt;/td&gt;
            &lt;td&gt;&lt;input name="id" type="text" id="id" value="&lt;?php echo $row['id'];?&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;filename&lt;/td&gt;
            &lt;td&gt;&lt;label for="filename"&gt;&lt;/label&gt;
            &lt;input name="filename" type="file" id="filename" value="&lt;?php echo $row['filename'];?&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;type&lt;/td&gt;
            &lt;td&gt;&lt;label for="type"&gt;&lt;/label&gt;
            &lt;input name="type" type="text" id="type" value="&lt;?php echo $row['type'];?&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;size&lt;/td&gt;
            &lt;td&gt;&lt;label for="size"&gt;&lt;/label&gt;
            &lt;input name="size" type="text" id="size" value="&lt;?php echo $row['size'];?&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;caption&lt;/td&gt;
            &lt;td&gt;&lt;label for="caption"&gt;&lt;/label&gt;
            &lt;input name="caption" type="text" id="caption" value="&lt;?php echo $row['caption'];?&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;caption_2&lt;/td&gt;
            &lt;td&gt;&lt;label for="caption_2"&gt;&lt;/label&gt;
            &lt;input name="caption_2" type="text" id="caption_2" value="&lt;?php echo $row['caption_2'];?&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;txt&lt;/td&gt;
            &lt;td&gt;&lt;label for="txt"&gt;&lt;/label&gt;
            &lt;textarea name="txt" id="txt" cols="45" rows="5"&gt;&lt;?php echo $row['txt']; ?&gt;&lt;/textarea&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
            &lt;td&gt;&lt;input type="submit" name="submit" id="submit" value="update"&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/table&gt;
      &lt;/form&gt;
  
  &lt;?php
      //4. release returned data
      //mysqli_free_result($result);
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;?php
      // 5. Zamkniecie bazy
      mysqli_close($connection);
  ?&gt;
  </code></pre>
  
  <p><strong>Action</strong></p>
  
  <pre><code>&lt;?php
  //1. polaczenie z baza danych
  //polaczenie z baza danych + ustawienie kodowania na utf8
  $dbhost = "localhost";
  $dbuser = "root";
  $dbpass = "3edcvfr4";
  $dbname = "dw_bookstore";
  $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
  
  //sprawdzenie polaczenia
  if (mysqli_connect_errno()) {
      printf("Connect failed: %s\n", mysqli_connect_error());
      exit();
  }
  
  //zmaiana znako na utf8
  if (!mysqli_set_charset($connection, "utf8")) {
      printf("Error loading character set utf8: %s\n", mysqli_error($connection));
  } else {
      printf("Kodowanie ustawione na: %s\n", mysqli_character_set_name($connection));
  }
  ?&gt;
  
  &lt;?php
  //2. przeslanie zdjecia wraz z danymi
  
  
      @$path = $_FILES["file"]["name"];
      @$type = $_FILES["file"]["type"];
      @$size = $_FILES["file"]["size"];
      $id = $_POST["id"];
      $caption = $_POST["caption"];
      $caption_2 = $_POST["caption_2"];
      $txt = $_POST["txt"];
  
      // przyklad - by moc wpisac 'costam' - tylko txt, nie "file" i "int"
      $caption = mysqli_real_escape_string($connection, $caption);
      $caption_2 = mysqli_real_escape_string($connection, $caption_2);
      $txt = mysqli_real_escape_string($connection, $txt);
  
      // 2. Perform database query
      $query  = "UPDATE photographs SET ";
      $query .= "id = '{$id}', ";
      $query .= "filename = '{$path}', ";
      $query .= "size = '{$size}', ";
      $query .= "type = '{$type}', ";
      $query .= "caption = '{$caption}', ";
      $query .= "caption_2 = '{$caption_2}', ";
      $query .= "txt = '{$txt}' ";
      $query .= "WHERE id = {$id}";
      echo $query;
  
      //$query  = "INSERT INTO photographs (";
      //$query .= "  filename, type, size, caption, caption_2, txt";
      //$query .= ") VALUES (";
      //$query .= "  '{$path}', '{$type}', '{$size}', '{$caption}', '{$caption_2}', '{$txt}'";
      //$query .= ")";
  
      $result = mysqli_query($connection, $query);
      if ($result) {
          // Success
          // redirect_to("somepage.php");
          echo " Sukces! Dane zostaly przeslane na serwer. ";
      } else {
          // Failure
          // $message = "Subject creation failed";
          die("Przeslanie danych nie powiodlo sie. " . mysqli_error($connection));
  
  
          if(isset($_POST['submit'])){
      if (((@$_FILES["file"]["type"] == "image/gif")
      || (@$_FILES["file"]["type"] == "image/jpeg")
      || (@$_FILES["file"]["type"] == "image/JPEG")
      || (@$_FILES["file"]["type"] == "image/jpg")
      || (@$_FILES["file"]["type"] == "image/png")
      || (@$_FILES["file"]["type"] == "image/pjpeg"))
      &amp;&amp; (@$_FILES["file"]["size"] &lt; 600000))
      {
          if ($_FILES["file"]["error"] &gt; 0)
          {
              echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br&gt;";
          }
          else
          {
          if (file_exists("../images/" . $_FILES["file"]["name"])){
                  echo $_FILES["file"]["name"] . " to zdjecie juz istnieje. ";
          }
          else{
          move_uploaded_file($_FILES["file"]["tmp_name"], "../images/" .              $_FILES["file"]["name"]);
  
  
                  echo " Przeslane do katalogu : " . "images/" . $_FILES["file"]["name"];
  
  
  
        }
       }
      }
     }
  }
  
  
  ?&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Update Action&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;?php
    // 5. Zamkniecie polaczenia
    mysqli_close($connection);
  ?&gt;
  </code></pre>