I’ve been struggling to write some code so that when a user logs in with their username and password the email address associated with that account can be displayed on the next page. I have created three rows in my mysql table: user_name, user_password and user_email.
Here is the code I have so far. I can log in to the account and everything works fine but I want to have ONLY the email address of the account that logs in to be displayed
[code=php] $this->db_connection = new mysqli(‘localhost’, ‘root’, ‘1’, ‘test’);
// create a database connection, using the constants from config/db.php (which we loaded in index.php)
if ($this->db_connection->connect_errno) {
echo “Connection Failed ” . $this->db_connection->connect_errno . “”;
}
// if no connection errors (= working database connection)
if (!$this->db_connection->connect_errno) {
// escape the POST stuff
$this->user_name = $this->db_connection->real_escape_string($_POST[‘user_name’]);
$this->user_password = $this->db_connection->$_POST[‘user_password’];
$user_name = $this->db_connection->real_escape_string($_POST[‘user_name’]);
// database query, getting all the info of the selected user
$sql = “SELECT user_name, user_password, user_email
FROM members
WHERE user_name = ‘” . $this->user_name . “‘”;
$query = $this->db_connection->query($sql);
$result = $query->fetch_object();
// if the username exists and if the password is a correct match
if (($query->num_rows == 1) && ($_POST[‘user_password’] === $result->user_password)) {
$_SESSION[‘user_name’] = $result->user_name;
$_SESSION[‘user_logged_in’] = 1;
$_SESSION[‘user_login_status’] = 1;
setcookie(“_time”, “cookie_value”, time() + 3600);
//redirect to this page if the user has logged in successfully
header(“Location: testing.php”);
}
else {
$this->errors[] = “Wrong username password combination”;
}