-1

I keep getting this message. I am simply trying to retrieve my table data from a sql db the line that is giving me the problem is: if ($result->num_rows > 0) {

In the code:

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

$result = $conn->query($prodlist);

if ($result->num_rows > 0) {
//     output data of each row
    while($row = $result->fetch_assoc()) {
        echo "Item Number: " . $row["item number"]. " - Item Description: " . $row["Item      Description"]."<br>";
   }
} else {
    echo "0 results";
}
$conn->close();
?>
</body>
</html>

1 Answers1

0

IF you did actually have a table field called item number you would have to quote it so : item number with backtick "`" characters hence you'd have to do the same in your query.

Cups
  • 6,901
  • 3
  • 26
  • 30