Get username from current PHP Session
<p>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 <code>uid</code> from the current session so I can welcome the user by their username.</p>

<pre><code>&lt;?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");
</code></pre>

<p>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.</p>

<pre><code>if (!$row == mysqli_fetch_assoc($result)) {
    echo "Your username or password is incorrect.";
} else {
    $_SESSION['id'] = !$row['$id'];
    $_SESSION['uid'] = !$row['$uid'];
}
</code></pre>