0

Why won't it display the database data? It instead displays Notice: Trying to get property of non-object in C:\wamp\www\h\index.php on line 43 No scripts

  <?php
  require("db.php");

  $sql = "SELECT id_scripts, name, url, desc, date FROM scripts ORDER BY id_scripts DESC LIMIT 4";
  $result = $conn->query($sql);

  if($result->num_rows > 0)
  {
  while($row = $result->fetch_assoc())
  {
      echo '<a href="' . $row["url"] . '">"' . $row["name"] . '"</a>' . $row["desc"];
  }
  } else {
      echo "No scripts";
  }
  $conn->close();
  ?>
svalis
  • 3
  • 1
  • 3
  • 1
    you have no error handling, and something blew up. start checking for errors. `$result = $conn->query($sql) or die($conn->error())`-type stuff. Never **EVER** assume success with database operations. always assume failure, check for failure, and treat success as a pleasant surprise. – Marc B Mar 10 '16 at 20:28
  • 3
    `desc` => https://dev.mysql.com/doc/refman/5.5/en/keywords.html – Funk Forty Niner Mar 10 '16 at 20:29
  • DESC is a reserve word use backticks.. (Table column) – devpro Mar 10 '16 at 20:30
  • 1
    @devpro or "front" ticks, depending on which side you're leaning ;-) – Funk Forty Niner Mar 10 '16 at 20:30

0 Answers0