i want a section (nft-section.php) in my users dashboard to display if the currently logged in user’s username is the same as the data in the “nftby” column of the table “nft”. So, I wrote this code
<?php
// Get the currently logged-in user's username from the session
$userName = $_SESSION['username'];
// Prepare the SQL statement
$query = "SELECT * FROM nft WHERE nftby = ?";
// Prepare the statement
$stmt = $conn->prepare($query);
if ($stmt === false) {
// Error handling: Display the error message
echo "Error preparing the SQL statement: " . $conn->error;
exit;
}
// Bind the username parameter
$stmt->bind_param("s", $userName);
// Execute the query
$result = $stmt->execute();
if ($result === false) {
// Error handling: Display the error message
echo "Error executing the SQL statement: " . $stmt->error;
exit;
}
// Get the result
$result = $stmt->get_result();
if ($result === false) {
// Error handling: Display the error message
echo "Error retrieving the result set: " . $stmt->error;
exit;
}
// Check if any matching records were found
if ($result->num_rows > 0) {
// Display the section of the website for the user
include 'nft-section.php';
} else {
// Display "No NFTs Yet"
echo "No NFTs Yet";
}
// Close the statement and database connection
$stmt->close();
$conn->close();
?>
and it isn’t displaying the section, or the error messages. But when I make use of only the
In your previous thread you were using the much simpler and more modern PDO database extension. In this thread you are using statement from the mysqli database extension, which would be producing fatal php errors, since you cannot mix statements for the two different extensions.
Do you have php’s error_reporting set to E_ALL and display_errors set to ON, preferably in the php.ini on your development system, so that php would help you by reporting and displaying all the errors it detects? Stop and start your web server to get any changes made to the php.ini to take effect and use a phpinfo(); statement in a .php script to confirm that the settings actually took effect.