Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Chuck Robertson
Chuck Robertson
3,408 Points

Why can I not query my database and get a result with this code?

The connect statement displays "Connected".

But I can't get it to query any result from the entry field.

<?php
$conn = new mysqli("localhost", "root", "", "test_db");
if ($conn->connect_errno) {
    echo "Failed to connect to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
} else {
  echo "Connected!";

}

$sql = $mysqli->query("SELECT * FROM basic_table");
$result = $conn->query($sql);

    while($row = $result->fetch_assoc()) {
      $entry = $row['entry'];
      echo "<p>$entry</p>";
    }


?>
andi mitre
andi mitre
Treehouse Guest Teacher

Do you have an entry attribute in your table?