[ PHP code displaying as comments in browser using WAMP ]
As is says in the title, my PHP code is showing up in the browser code inspector like it is commented out. For example,
<?
include("assets/php/dbconn.inc.php");
$conn = dbConnect();
$sql = "SELECT * FROM movies";
$rs = $conn->query($sql) or die ("Movie query failed");
$number_of_rows = $rs->num_rows;
while($row = $rs->fetch_assoc()){
echo("{$row['title']}");
}
?>
displays in the browser as
<!--?
include("assets/php/dbconn.inc.php");
$conn = dbConnect();
$sql = "SELECT * FROM movies";
$rs = $conn--->
and the rest of the code prints on the webpage.
I am testing this using WAMP on my local machine. Any idea where these comment tags are coming from?
Answer 1
Never use short open tag <?
for your PHP code block. Always use long tags <?php
, because short tag can be disabled in php.ini
(which is your case) which results in just displaying your source code.
Answer 2
Posted on behalf of the OP:
SOLVED I was navigating to the file directly instead of through the localhost address. Rookie mistake.