An error in my query that I cannot quite figure out - no error code or anything, just error

so I am doing a project which is basically a website, which can/could be used to look up cars other users have put up for sale and I have just ran into in error(well not just, a good 4 hours before..) which I can't quite figure out what is the problem, so the solution can be pretty bisare, but I just can't find it..

So the problem is, that when you click 'Podrobnosti'(which means details), there should be a popup that serves you the wanted data from the database(I know this isn't the way, but I am just looking for correct data at this stage).

<?php

session_start();
include 'head.php';

if ($_SESSION["type"] == 1) {
  include 'admin-meni.php';
} else {
  include 'meni.php';
}

$servername = "localhost";
$username = "root";
$password = "";
$db = "avto_test";

// Create connection
$conn = new mysqli($servername, $username, $password, $db);

$sql = "SELECT z.opis as znamka, m.opis as model, a.letp_p_r, p.cena, a.id_avta
          FROM avto a 
          JOIN model m   ON a.id_modela = m.id_modela
          JOIN znamka z  ON m.id_znamke = z.id_znamke
          JOIN prodaja p ON a.id_avta = p.id_avta
         WHERE p.active = 1
      ORDER BY p.id_prodaje DESC";

$result = $conn-> query($sql);
if ($result-> num_rows > 0) {
  echo "<div id='katalog'>";
  while ($row = $result-> fetch_assoc()) {

    echo "<div class='avto'>";

?>

<form method="post" action="katalog.php"> 

<?php

    echo "<p>" . $row["znamka"] . " " . $row["model"] . "</p>";
    echo "<p class='cena'>Cena: " . $row["cena"] . "€</p>";
    echo '<input type="number" value="' .$row["id_avta"] .'" name="id_avta">';
    echo '<input type="submit" name="details" value="Podrobnosti"/></form>';
    echo "</div>";
  }
  echo "</div>";
}

if (isset($_POST['id_avta'])) {
  // Create connection
  $conn = new mysqli($servername, $username, $password, $db);
  if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
  }

  $sql = "SELECT a.*, g.opis as gorivo, m.opis as menjalnik, mo.opis as model, z.opis as            znamka
            FROM avto a
      INNER JOIN gorivo g    ON g.id_goriva = a.id_goriva 
      INNER JOIN menjalnik m ON m.id_menjalnika = a.id_menjalnika
      INNER JOIN model mo    ON mo.id_modela = a.id_modela
      INNER JOIN znamka z    ON mo.id_znamke = z.id_znamke
           WHERE a.id_avta = " .$_POST["id_avta"] .";";

  if ($conn->query($sql) === TRUE) {
    echo '<script language="javascript">alert(zdej se je query izvedu)</script';
    $result = $conn-> query($sql);
    $rowcount = mysqli_num_rows($result);
    if ($rowcount == 1) {
      while ($row = $result->fetch_assoc()) {
        echo "<script language='javascript'>
        alert(Znamka: " . $row["znamka"] .")</script>";
      }
    } else {
      echo '<script language="javascript">alert(ni enako ena)</script';
    }
  } else {
    echo "Error: " . $sql . "<br>" . $conn->error;
  }
  $conn->close();
}

?>

(Look from the isset(.$_POST[id_avta]), the whole document is there just for refference)

The problem is, that when clicking the button just a paragraph saying:

Error: SELECT a.*, g.opis as gorivo, m.opis as menjalnik, mo.opis as model, z.opis as znamka FROM avto a INNER JOIN gorivo g ON g.id_goriva = a.id_goriva INNER JOIN menjalnik m ON m.id_menjalnika = a.id_menjalnika INNER JOIN model mo ON mo.id_modela = a.id_modela INNER JOIN znamka z ON mo.id_znamke = z.id_znamke WHERE a.id_avta = 8; 

appears, which is basically Error written in from of the query, which, if I run it directly on the server, outputs correct data.

Thank you in advance :D