0

After migrating from localhost to webserver I'm getting this error. Maybe it could be because of the PHP version on webserver (PHP 5.2). Any ideas?

<?php
$servername ="";
$username ="uran";
$password ="";
$dbname ="";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT * FROM answer WHERE topic_key='$id'";
$result = $conn->query($sql);
 // output data of each row
while($row = $result->fetch_assoc()) {
    echo "<strong>Príspevok č.:</strong> " . $row["id"]. "<br>"."     <strong>Napísal:</strong> " 
    . $row["name"]. "<br>". $row["topic"]."<br>" . $row["reg_date"]."<br>"."  <br><br>";
}

$conn->close();
 ?>
trenccan
  • 720
  • 3
  • 7
  • 19

1 Answers1

0

I think that your query fails to that $conn->query($sql) will return FALSE (see mysqli::query).

Please add the following code to your code to get the error message:

if (!$result) {
    printf("Error: %s\n", $conn->error);
}
mario.van.zadel
  • 2,919
  • 14
  • 23