Trying to connect database in PHPMyAdmin and Query Database

Hi: I am trying to show database (on phpmyadmin) data using MySqli. I have created a database handler using the following code:

<?php

$dbServername = “locahost“;

$dbUsername = ”root”;

$dbPassword = “ ”;

$dbName = “march4”;

$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);

I have created an php that references the database handler (above) to select data from the table ‘books’ in a database called ‘march4’ (in my phpadmin). However I am getting a Parse error T_STRING on line #14 in the following code:

<?php
      include _once (‘dbh.php’);
?>

<!DOCTYPE html>
<html>
<head>
             <title></title>
</head>
<body>

<?php
           
$sql = “SELECT * FROM books”;  // line 14
           $result = mysqli_query($conn, $sql);
            $resultcheck = mysqli_num_rows($result);
            
            if ($resultcheck > 0) {
                while ($row = mysqli_fetch_assoc($result))  {
                echo $row[‘Author’];
             }
        }
?>


</body>
</html>

Please help!

What is included in ‘dbh.php’ ??

I looks like you are following a tutorial of some kind? You have to put your connection credentials in the the “dbh.php” file would be my guess. You also have to setup your MySQL Database Table as well.

Wherever you copied the code from, it was ‘published’ with smart/curly quotes, making it useless as actual php code. You need to delete and re-type all the single and double quotes so that they are ascii quotes ' and ".

My database table is set up in phpmyadmin with the approriate database name and table names. I have the database handler file created and have created an index file that references the handler. However, the problem is in line #14 of the index file- I am getting a Parse error T_STRING on line #14 (see code below).

<?php include _once (‘dbh.php’); ?> <?php $sql = “SELECT * FROM books”; // line 14 $result = mysqli_query($conn, $sql); $resultcheck = mysqli_num_rows($result); if ($resultcheck > 0) { while ($row = mysqli_fetch_assoc($result)) { echo $row[‘Author’]; } } ?>

dbh.php is the datbase handler and the code is as follows:

<?php $dbServername = “locahost“; $dbUsername = ”root”; $dbPassword = “ ”; $dbName = “march4”; $conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);

If your actual code has the curly quotes as shown you need to replace with straight quotes.

That winds me up when I have to do that lol.

Sponsor our Newsletter | Privacy Policy | Terms of Service