title: IMG path to db and then show it
body: <p>I'm trying to upload image path to DB in a table with next structure:</p>
  
  <p><a href="https://i.stack.imgur.com/urYKb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/urYKb.png" alt="enter image description here"></a></p>
  
  <p>This is HTML (I did not include other form-groups, only image one.):</p>
  
  <pre><code>&lt;?php 
  
  include "src/post/Image.php";
  
  $connection = new Db();
  $conn = $connection-&gt;connect();
  
  $image = new Image();
  $img = "";
  
  $query = "SELECT * FROM category";
  $result = mysqli_query($conn, $query);
  
  if(isset($_POST['publish'])){
  
      $img = $image-&gt;insertimg();
  
  }
  
  ?&gt;
  
  
  &lt;form role="form" method="post" enctype="multipart/form-data"&gt;
  
  &lt;div class="form-group"&gt;
  
      &lt;label for="image"&gt;
          File input
      &lt;/label&gt;
  
      &lt;input type="file" name="image" class="form-control-file" id="image" required&gt;
  
  &lt;/div&gt;
  
  &lt;button type="submit" name="publish" class="btn btn-dark"&gt;
      Publish
  &lt;/button&gt;
  
  &lt;/form&gt;
  
  
  &lt;?php
  
  $data = "SELECT * from post" or die(mysqli_error());
  
  $result1 = mysqli_query($conn, $data);
  
  while($info = mysqli_fetch_array($result1)){
  
      echo "&lt;tr&gt;";
      echo "&lt;td&gt;&lt;img src='images/$info[0].jpg'&gt;&lt;/td&gt;";
      echo "&lt;/tr&gt;\n";
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>And this is a class:</p>
  
  <pre><code>&lt;?php
  
  include "src/db/Db.php";
  
  
  class Image{
  
  public $target = "images/";
  public $title;
  public $category;
  public $description;
  public $text;
  public $pic;
  
  public function insertimg(){
  
      $connection = new Db();
      $conn = $connection-&gt;connect();
  
      $this-&gt;target = $this-&gt;target . basename($_FILES['image']['name']);
  
      $query = $conn-&gt;prepare("INSERT INTO post(title, category, description, text, image) 
      VALUES (?, ?, ?, ?, ?)");
      $query-&gt;bind_param('sssss', $this-&gt;title, $this-&gt;category, $this-&gt;description, $this-&gt;text, $this-&gt;pic);
  
      $this-&gt;title = $_POST['title'];
      $this-&gt;category = $_POST['selectcategory'];
      $this-&gt;description = $_POST['description'];
      $this-&gt;text = $_POST['text'];
      $this-&gt;pic = ($_FILES['image']['name']);
  
      $query-&gt;execute();
  
      if(move_uploaded_file($_FILES['image']['tmp_name'], $this-&gt;target)){
  
          echo "&lt;script&gt; alert('Image inserted into database.') &lt;/script&gt;";
  
      } else{
  
          echo "&lt;script&gt; alert('Error.') &lt;/script&gt;";
  
      }
  
  }
  
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>Last, this is my 'file structure' (I post this because think I made some kind of "path" error):</p>
  
  <p><a href="https://i.stack.imgur.com/ngzrJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ngzrJ.png" alt="enter image description here"></a></p>
  
  <p>An error:</p>
  
  <p><a href="https://i.stack.imgur.com/YotGm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YotGm.png" alt="enter image description here"></a></p>
  
  <p>When I click <code>publish</code> it shows an error alert.</p>
  
  <p>Then >
  34 is <code>if(move_uploaded_file($_FILES['image']['tmp_name'], $this-&gt;target))</code></p>
  
  <p>On the page where I'm trying to show it:</p>
  
  <p><a href="https://i.stack.imgur.com/B4HCw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B4HCw.png" alt="enter image description here"></a> depends of the size.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is what I did in <code>&lt;img&gt;</code> :</p>
  
  <pre><code>echo "&lt;td&gt;&lt;img src='src/post/images/" .$info[0].".png' /&gt;&lt;/td&gt;";
  </code></pre>
  
  <p>Hardcoded <code>.png</code> because my image file has that extension.</p>
  
  <p>So when I open an image on a new page path is <code>marenews/src/post/images/14.png</code> </p>
  
  <p>and in that way its working.</p>
  
  <p>How to get rid of that?</p>
  
  <p><strong>LAST EDIT:</strong></p>
  
  <p>I did it. (var_dump saved me)</p>
  
  <pre><code> echo "&lt;td&gt;&lt;img src='src/post/images/" .$info[5]."' /&gt;&lt;/td&gt;";
  </code></pre>
  
  <p>[5] or #6 in the DB table is an image path. Now i don't need a hardcoded extension.</p>