I'm scratching my head over this one, the typical way I write this is not working and I am at a loss as to why. I'm building a user login form, and building the query based off of the input values. When I mess with this line I lose all variables.

These two formats I end up with NOTHING displayed as far as my 3 variables are concerned:

PHP Code:
$SQLGetUser "SELECT user_id, username FROM user WHERE username='" $loginuser "' AND password='" $loginpassword "'"
PHP Code:
$SQLGetUser "SELECT user_id, username FROM user WHERE username='$loginuser' AND password='$loginpassword'"
But changing it to THIS

PHP Code:
$SQLGetUser "SELECT user_id, username FROM user WHERE username=$loginuser AND password=$loginpassword"
All the variables get set as I expect, but my SQL is not good because I lose my quote marks around my 2 values for the MySQL database so the query fails.

Even if I put in a line with the exact SQL Query it ends up making all the variables report empty. Maybe it is in my redirecting after the form reloads?

Here is the entire snippet of login code:

PHP Code:
if(isset($_POST['submit']))
  {
    
$loginuser $_POST['loginuser'];
    
$loginpassword md5($_POST['loginpassword']);
    if((!empty(
$loginuser)) or (!empty($loginpassword)))
    {
      
$SQLGetUser "SELECT user_id, username FROM user WHERE username='" $loginuser "' AND password='" $loginpassword "'";
      
$result mysqli_query($link$SQLGetUser);
      if(
$result)
      {
        
session_start();
        while(
$row mysqli_fetch_assoc($result))
        {
          
$_SESSION['user_id'] = $row['user_id'];
          
$user_id $row['user_id'];
        }
        
header('Location: index.php?user_id=' $user_id);
        exit();
      } else {
          
$errornotice "Unable to log you in.";
      }
    }
  } 
Any guidance will be GREATLU appreciated as I have been staring at this code for over a day now and, while I KNOW it is some stupid thing I am not thinking through correctly, I can't seem to get my head wrapped into it so I can see where I've gone wrong. The strange thing is I have this almost exact same code on another page, and it pulls the values back from the database just as I expect.

Thanks in advance for any suggestions!

Greg