SELECT statement does not work correctly with passed variable forms

I have a page that receives form data from a submitted form, I wrote a SELECT statement to search my database on page load (from a form submit) and the POST form variables are generated. The problem I am facing is this query returns 0 results using the $ aircraftMake variable, but when I enter a static value instead of a variable, I get the results I want. I am completely new to this, so any help would be appreciated. I have listed the below code.

    <?php 
$aircraftMake = mysqli_real_escape_string($conn, $_POST['marke']);
$aircraftModel =  mysqli_real_escape_string($conn, $_POST['model']);
$engine =  mysqli_real_escape_string($conn, $_POST['Motorisation']);
?>

</head>

<body>

<?php
$sql = "SELECT * FROM QuoteData WHERE aircraftMake = '$aircraftMake'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo $row["aircraftMake"]. "<br>" . $row["aircraftModel"]. "<br>" . $row["engineModel"]. "<br>" . $row["overhauledEngineSteelCylinders"]. "<br>" . $row["overhauledEngineNickelCylinders"]. "<br>" . $row["overhauledEngineNewCylinders"]. "<br>" . $row["individualOverhauledSteelCylinder"]. "<br>" . $row["setOfFourOverhauledSteelCylinders"]. "<br>" . $row["individualOverhauledNickelCylinder"]. "<br>" . $row["setOfFourOverhauledNickelCylinders"]. "<br>" . $row["engineCoreValue"]. "<br>" . $row["note1"]. "<br>" . $row["note2"]. "<br>" . $row["note3"]. "<br>" . $row["OverhaulIncludes"]. "<br>" . "<br>" .  $row["shippingToInclude"];
    }
} else {
    echo "0 results";
}
$conn->close();
?>

      

+3


source to share


2 answers


The code looks ok, are you sure your data is set $_POST

?



<?php
  if(isset($aircraftModel)){
     // code here
  }

      

0


source


try it



 $sql = "SELECT * FROM QuoteData WHERE aircraftMake = '".$aircraftMake."'";

      

-1


source







All Articles