Home > front end >  HTML and PHP error- Unexpected end of file
HTML and PHP error- Unexpected end of file

Time:10-01

recently I have been having some errors with PHP and it's currently asking me to fix an unexpected end of file error, despite already copying the solutions provided here, it still doesn't work.

<!DOCTYPE html>
<html>
<body>
<?php
//session_start();
$servername = "servername";
$username = "username";
$password = "Password";
$dbname = "databasename";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
$result = mysqli_query($con,"SELECT * FROM RecordDetails");
echo "<table border='0'>
      <tr>
      <th>Record Cover</th>
      <th>Record Name</th>
      <th>Artist Name</th>
      <th>Record Price</th>
      </tr>";
while($row = mysqli_fetch_array($result)){
  echo "hello";
  echo "<tr>";
  echo "<td> <img src=\"<?php $row['AlbumCover']?>\"</td>";
  echo "<td><b>" . $row['RecordName'] . "</b></td>";
  echo "<td>" . $row['ArtistName'] . "</td>";
  echo "<td>" . $row['RecordPrice'] . "</td>";
  echo "</tr>";
   }
$conn->close(); 
?>
</body>
</html>'

CodePudding user response:

First,

echo "<td> <img src=\"<?php $row['AlbumCover']?>\"</td>";

should be

echo "<td> <img src=\"" . $row['AlbumCover'] . "\"></td>";

You cannot put PHP inside a string.

CodePudding user response:

Replace your below line

echo "<td> <img src=\"<?php $row['AlbumCover']?>\"</td>"; 

to

echo "<td> <img src=\"' . $row['AlbumCover'] . '\"></td>";

and remove single comma in end of html like </html>' to </html>

  • Related