I need to echo a row from mysql database. When i echo this in the start (php) it works, but when in html, it doesn't work. Do i need to include something or what? I'm not very good with php, just learning...
It doesn't work in html because $row variable is visible only in the while loop scope!
while($row = $result->fetch_assoc()) {
if($_GET['email'] != $row["email"]){
echo "ERROR: Emails don't match! <br>";
echo "Please try again!";
exit();
$conn->close();
}
echo "Ticket Information: <br>";
echo "Ticket: #" . $row["id"]. " - Name: " . $row["username"]. " - Message: " . $row["Message"]. "<br>";
echo "MySQL: ";
echo $row["email"];
}
Try something like this:
while($row = $result->fetch_assoc()) {
if($_GET['email'] != $row["email"]){
echo "ERROR: Emails don't match! <br>";
echo "Please try again!";
exit();
$conn->close();
}
$rowId = $row["id"];
echo "Ticket Information: <br>";
echo "Ticket: #" . $row["id"]. " - Name: " . $row["username"]. " - Message: " . $row["Message"]. "<br>";
echo "MySQL: ";
echo $row["email"];
}
In HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<title>MrRockis's Website</title>
</head>
<body>
// Here i want to echo my ticket ID!
<b>Ticket ID:<b> <?php echo $rowId; ?>
</body>
</html>