I am new to PHP and am trying to create a member login. I am paying with this code block and was curious as to see how I can get the username or uid
from the current session so I can welcome the user by their username.
<?php
session_start();
include 'db.php';
$uid = $_POST['uid'];
$pwd = $_POST['pwd'];
$sql = "SELECT * FROM users WHERE uid='$uid' AND pwd='$pwd'";
$result = mysqli_query($conn, $sql);
if (!$row == mysqli_fetch_assoc($result)) {
echo "Your username or password is incorrect.";
} else {
$_SESSION['id'] = !$row['$id'];
}
header("Location: index.php");
I tried this if statement to display the username but it displayed no result at all. My thought is that if that statement is displaying the ID of the user the same line would get the uid but that is not working.
if (!$row == mysqli_fetch_assoc($result)) {
echo "Your username or password is incorrect.";
} else {
$_SESSION['id'] = !$row['$id'];
$_SESSION['uid'] = !$row['$uid'];
}