0

I've been trying to create a web application that functions like a library system, and I am currently working on building the table that will display all books in the system. However, after I close the first echo statement to start building the table in HTML, the app seems to just stop seeing it as code and prints the rest of the PHP code to the screen.

Here is the code in question:

<?php
        $db = mysqli_connect('34.224.99.227','root','opendoor','library')
            or die ('Could not connect to database');

        $result = mysqli_query($db,'SELECT * FROM book');

        echo '<table id="table_id" class="display">
              <thead>
                <tr>
                    <th>ISBN</th>
                    <th>Title</th>
                    <th>Author</th>
                    <th>Description</th>
                    <th>Status</th>
                </tr>
               </thead>
               <tbody>';

        while($row = mysqli_fetch_array($result)) {
            echo '<tr>';
            echo '<td>' . $row['isbn'] . '</td>';
            echo '<td>' . $row['title'] . '</td>';
            echo '<td>' . $row['author'] . '</td>';
            echo '<td>' . $row['description'] . '</td>';
            echo '<td>' . $row['status'] . '</td>';
            echo '</tr>';
        }

        echo '</tbody></table>';

        mysqli_close($db);
    ?>

And here is the corresponding web page output:

ISBN Title Author Description Status '; while($row = mysqli_fetch_array($result)) { echo ''; echo '' . $row['isbn'] . ''; echo '' . $row['title'] . ''; echo '' . $row['author'] . ''; echo '' . $row['description'] . ''; echo '' . $row['status'] . ''; echo ''; } echo ''; mysqli_close($db); ?>

I'm obviously not too well-versed in PHP, so I'm at a loss as to what the problem could be.

7
  • opening php tags? *.php file name? running on a server with php? Commented Mar 25, 2018 at 21:12
  • Added the full php section. It is a php file. It's a local file right now. Commented Mar 25, 2018 at 21:18
  • There are no errors in that code you supply Commented Mar 25, 2018 at 21:19
  • local file, but you are running a web server and php? accessing the file via http://(local ip address) with a browser? Commented Mar 25, 2018 at 21:20
  • Do you have HTML tags for html, head, body DOCTYPE etc. anywhere in there? Commented Mar 25, 2018 at 21:20

1 Answer 1

1

After playing around with the settings of my LAMP stack, I realized that I had apparently configured it with PHP 5 in mind, while I had downloaded PHP 7. Once I fixed the discrepancy, everything worked as intended. Thanks for help nonetheless.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.