How to check var mail user
To check the value of a variable named mail
for a user in PHP, you can use the following methods:
Method 1: Using the $_SESSION
superglobal
if (isset($_SESSION['mail'])) {
echo $_SESSION['mail'];
} else {
echo 'No mail address found';
}
This method assumes that you have stored the user's mail address in a session variable named mail
using $_SESSION['mail'] = $user_mail;
earlier in your code.
Method 2: Using a database query
// Assuming you have a database table named 'users' with a column named 'mail'
$query = "SELECT mail FROM users WHERE id = '$user_id'";
$result = mysqli_query($conn, $query);
if ($result && mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
echo $row['mail'];
} else {
echo 'No mail address found';
}
This method assumes that you have a database connection established and a query that retrieves the user's mail address from the users
table based on their ID.
Method 3: Using an object-oriented approach
// Assuming you have a User class with a property named 'mail'
$user = new User($user_id);
if ($user->getMail()) {
echo $user->getMail();
} else {
echo 'No mail address found';
}
This method assumes that you have a User class with a method getMail()
that returns the user's mail address.
Remember to replace $user_id
with the actual ID of the user you want to retrieve the mail address for.