0

Why is this PHP code wrong in the browser? I don't think there's anything wrong. Error: enter image description here

This is the <body> code:

    <body>
        <center>
            <div class="header">
                MySQL Results
            </div>
        </center>
        <?php
            include_once 'db_functions.php';
            $db = new DB_Functions();
            $users = $db->getAllUsers();
            if ($users != false)
                $no_of_users = mysql_num_rows($users);
            else
                $no_of_users = 0;

        ?>
        <?php
            if ($no_of_users > 0) {
        ?>
        <table>
        <tr id="header"><td>Id</td><td>Username</td></tr>
        <?php
            while ($row = mysql_fetch_array($users)) {
        ?> 
        <tr>
        <td><span><?php echo $row["Id"] ?></span></td>
        <td><span><?php echo $row["Name"] ?></span></td>
        </tr>
        <?php } ?>
        </table>
        <?php }else{ ?>
        <div id="norecord">
        No records in MySQL DB
        </div>
        <?php } ?>
        <div class="refresh">
        <button onclick="refreshPage()">Refresh</button>
        </div>
    </body>
Gilsha
  • 14,431
  • 3
  • 32
  • 47
kevin4z
  • 349
  • 4
  • 12

1 Answers1

1

It looks as though your web server is "preventing" PHP execution properly - and escaping the opening PHP tags <?php to a HTML comment <!--.

What are you hosting the application on? I'd start by looking for issues there. Your code is fine.


Update: It's been stated the OP is running Apache Tomcat. I've very little experience of it, but I'm willing to speculate it's the configuration of it which is causing the problem. (Possibly there is no PHP runtime even installed.)

This SO question seems relevant: Run a php app using tomcat?

Otherwise I'd suggest to try hosting it someplace else - where it's just straight Apache + PHP.

One of the StackOverflow sister sites might be better placed for dealing with the server questions if you get stuck configuring it (maybe http://unix.stackexchange.com)

Community
  • 1
  • 1
wally
  • 3,492
  • 25
  • 31
  • I use `Apache Tomcat 7.0` – kevin4z Oct 09 '15 at 08:17
  • Is this on your own server, where you have root access via SSH etc? If it is - which OS? For Debian/Ubuntu it'd be helpful to see the output of "apt-get list installed | grep php" and for CentOS/RedHat "yum list installed | grep php", others YMMV. I'll start by guessing you've not got PHP modules enabled. (Tomcat is for Java, not PHP.) – wally Oct 09 '15 at 08:19