I just set up a new Ubuntu 12.04 LTS 64-bit server, picking whatever package for Apache it came with. I’m trying to open this index.html file in my browser:
<html><body><h1>Testing Database</h1>
<?php
$con=mysql_connect("localhost","****","****");
if(!$con) {die('Could not connect: ' . mysql_error());
mysql_select_db("Test", $con);
$result=mysql_query("SELECT * FROM main");
while($row=mysql_fetch_array($result))
{
echo $row['id'] . " " . $row['name'];
echo "<br />";
}
mysql_close($con);
?>
</body></html>
I had created a database and table in MySQL. I made a phpinfo.php file (containing <?php phpinfo(); ?>) that ran just fine. But for some reason, Internet Explorer only shows the title [Testing Database], and Chrome shows just the title, plus:
"; } mysql_close($con); ?>
I’m following a tutorial here, is there something wrong with my setup? I feel like I’m missing some sort of parenthesis in this tiny chunk of code, but cannot find it.
index.html?
.htmlpages won’t parse as PHP, you need to have the.phpextention, or use some htaccess to force it through the PHP parser.Other than that, there was a syntax error in your file, change to:
notice the removal of the
{from this line: