user3088745
user3088745

Reputation: 77

PHP isn't actually executing

I have the code below and when I try to open the page I get the message

"; } // Close the database connection mysql_close($con); ?>

As you can see I closed it. Can someone please help me. Thanks.

<html>
<head>
<title>Retrieve data from database </title>
</head>
<body>

<?php

$host='localhost';
$user='xxxxx';
$pass='xxxxx';
$database='xxxxx';

// Connect to database server
$con=mysql_connect($host, $user, $pass) or die (mysql_error ());

// Select database
mysql_select_db($database) or die(mysql_error());

// SQL query
$strSQL = "SELECT * FROM contact_list";

// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);

// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array
while($row = mysql_fetch_array($rs)) {

   // Write the value of the column LastName (which is now in the array $row)
  echo $row['lastname'] . "<br />";

  }

// Close the database connection
mysql_close($con);

?>
</body>
</html>

Upvotes: 0

Views: 74

Answers (1)

Carlos Robles
Carlos Robles

Reputation: 10947

You are not getting an error or suggestion to close your data base, what you are getting is your own code. This is a problem with your tags, or your quotation marks. please revise all

UPDATE

actually, your server is not running any php. It is reading everyting as a big tag starting at <?php and ending at the /> that you have in the line echo $row['lastname'] . "<br />";

Probably your file hasnt the php extension, or your server hasnt php available, or something is not well configured

Upvotes: 1

Related Questions