So I'm using sql with php but one variable doesn't work. The variable $pagina works in the $sql but not within the else {} ($sql2 and header). The other variables do work ($naam and $bericht). Can anyone spot the mistake?
(Sorry for any possible mistakes in my English.)
<?php
$bericht = $_POST ['bericht'];
$pagina = $_GET ['id'];
$naam = $_SESSION['login'];
$con = mysqli_connect("host","sql","pw","sql");
if (empty($bericht)) {
}
else
{
$sql2="INSERT INTO Comments (bericht_id, naam, bericht) VALUES ('$pagina', '$naam', '$bericht')";
mysqli_query($con,$sql2);
header("location:directbericht.php?id=$pagina");
}
$sql="SELECT * FROM Berichten WHERE id = $pagina";
if ($result=mysqli_query($con,$sql))
{
while ($obj=mysqli_fetch_object($result))
{
echo $obj->naam;
echo "<br><br>";
echo $obj->bericht;
echo "<br><br>";
echo $obj->datum;
echo "<br><br>";
}
}
$sql="SELECT * FROM Comments WHERE bericht_id = $pagina ORDER BY id ASC";
if ($result=mysqli_query($con,$sql))
{
while ($obj=mysqli_fetch_object($result))
{
echo "<tr><td><font color='white'>";
echo $obj->naam;
echo "<br><br>";
echo $obj->bericht;
echo "<br><br>";
echo $obj->datum;
echo "<br><br>";
echo "</font></tr></td>";
}
}
?>