I am trying to load data from MySQL and then display the results. I would like be able to delete the associated record as well.
<?php
include 'conn.php';
$sql = "SELECT * FROM Reviews LIMIT 3";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<h1> " . $row["rTitle"]. " </h1>" . $row["rText"]. "<br> <a href="delete.php?id={$row['id']}">Delete</a>";
}
} else {
echo "0 results";
}
$id = $_GET['rID'];
mysql_query("DELETE FROM Reviews WHERE id = {$id}");
$conn->close();
?>
I have a problem with this line:
echo "<h1> " . $row["rTitle"]. " </h1>" . $row["rText"]. "<br> <a href="delete.php?id={$row['id']}">Delete</a>";
Error: syntax error, unexpected 'delete' (T_STRING), expecting ',' or ';
What am I doing wrong? Thank you.
" . $row["rTitle"]. "
" . $row["rText"]. "Delete";` **OR** `echo "
{$row['rTitle']}
{$row['rText']}Delete";` – danish-khan-I May 30 '19 at 09:21