what happens is that I already have my connection to the database made but when I want to show that data.
I get this error:
( ! ) Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\wamp64\www\projects\news\articles.php online 18
I attach my code thanks:
<?php require_once "./includes/head.php"; ?>
<link rel="stylesheet" href="./assets/css/articulos.css">
<?php require_once "./includes/header.php" ?>
<section class="notices">
<div class="container">
<div class="info">
<h2>Ultimas Noticias</h2>
<h3>Conozca las ultimas noticias de nuestro colegio</h3>
</div>
<div class="grid">
<?php
$query = mysqli_query($database, "SELECT titulo, descripcion, fecha, imagen FROM articulos");
$result = mysqli_query($database, $query);
while ($mostrar = mysqli_fetch_array($result)) {
echo "<div> $mostrar['titulo'] </div>";
}
?>
</div>
</div>
</section>
<?php require_once "./includes/footer.php" ?>
In the editor, the first single quote of is marked in red $mostrar['titulo'];
.
PS: The include head contains the one
conexion.php
from the database.
When you are going to show dynamic code interspersed with static code, as in this case it is PHP with HTML, you should leave it like this:
So you concatenate the HTML tags wrapped in quotes with the variable created in PHP.
Otherwise the closing symbol on
>
the HTML side causes a conflict in PHP.