0

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>
2

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! I forgot to add some packages on the server. It is working now. You were exactly right

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.