简体   繁体   中英

Database Connected, but no data found

I have created this page, I have put dummy content into MySQL database, I have ran the same query in phpMyAdmin and it brings back data, yet on the web page it is bringing up "No Data".

Have I missed something? (obviously blanked out database details)

<?php

// Connection Info
$host ='localhost';
$user ='-----';
$pass ='-----';
$dbname ='-----';

$conn = new mysqli($host, $user, $pass, $dbname);

if($conn->connection_errno){

    echo "Connection Failed" . $conn->connect_error;
    exit();
}
?>

<?php
$query = "SELECT * FROM posts";
$result = $conn->query($query);

if($results->num_rows > 0){
    while($row = $result->fetch_assoc()){
        echo $row['title'];
    }
    echo"We Have Data";
} else {
    echo"No Data";
}

?>

Change the following line

if($results->num_rows > 0){

to

if($result->num_rows > 0){

He typo mistake friend

Make following changes in to your code

From if($results->num_rows > 0){

To

if($result->num_rows > 0){

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM