Not doing the if statement PHP

655 views php

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.


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

                        $conn =  new mysqli($servername, $dbname);
                        $sql = "SELECT ID, Title, Description, Month FROM 
                        $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";

answered question

2 Answers


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

posted this

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

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

posted this

Have an answer?


Please login first before posting an answer.