-1

It does straight to 0 results found on my website instead of doing the echo $row any ideas? I want it to pull from my database(phpmyadmin) the database name is events_table on it.

<?php

$servername = "localhost";
$dbname = "events_table";




$conn =  new mysqli($servername, $dbname);
$sql = "SELECT ID, Title, Description, Month FROM 
                              'events_table'";
$result = $conn->query($sql);


if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());

}




if ($result = $conn->query($sql)){
    echo "query success";


    while($row =  $result->fetch_assoc()) {
        echo $row["ID"],  $row["Title"], $row["Description"] ;
    }
}
else {

    echo "0 Results";
}
$conn->close();
?>
Dharman
  • 26,923
  • 21
  • 73
  • 125

2 Answers2

1

Do not wrap your table name between '', use backtick ` instead, it's parse syntax error. So your query does not have 0 results, its failing.

You should really turn up your error reporting tho

Andrea Golin
  • 2,929
  • 1
  • 14
  • 22
0

You have $conn = new mysqli($servername, $dbname); which is missing some parameters

// Hostname: 127.0.0.1, username: your_user, password: your_pass, db: sakila
$mysqli = new mysqli('127.0.0.1', 'your_user', 'your_pass', 'sakila');

http://php.net/manual/en/mysqli.examples-basic.php

  • I think this helps but now I am getting a new error message have tried with default username and password so have setup another one with full privileges still not working the error message is- Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'events_table'@'localhost' (using password: YES) in C:\xampp\htdocs\index.php on line 103 – Allin1gamer Nov 08 '18 at 19:26