Why is this PHP code wrong in the browser? I don't think there's anything wrong. Error:
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>
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)