Skip to main content
Participant
May 23, 2012
Question

personalized welcome message

  • May 23, 2012
  • 4 replies
  • 966 views

Hi all, I am having a small issue and I believe it has something to do with that my where clause in mysql that I am missing here. I am using Dreamweaver CS5 and MySQL database.  I have created a log in page and my database is updating with the usernames and passwords. So thats all good.   Now once they are logged into the members.php page I would like to have a Welcome logged in username, message to the top of the page.  Just like the one at the top of this page.

I have created a recordset like this

SELECT username

FROM users

When I click the test button I do see all the user names in my database table called users.  So it does work however its only pulling the very first username (that I entered into my database) no matter who's logged in. Which is not cool if Billy Bob or Susie Q is logged in and he/she sees a Welcome Kristy, message!  

I did a simple google search and there was a post about needing to put  a where clause of MM_users which I did try but but got an error message in sql about unknown column in MM_users in where clause. Could someone help point me to the right where clause if I do infact need one or what I need to change to have the welcome logged in username displayed at the top of the page.  Thank you so much

Kristy S.

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Rob Hecker2
Legend
May 23, 2012

You query will look something like this:

SELECT username FROM users WHERE username = '$username'

Before you can run this, the variable $username must be populated. If you are using SESSIONS for your user credentials, then it would be something like this:

$username = $_SESSIONS['username'];

In one place you call the table "users" and in another you call it MM_users. You must be exact about your table and column names.

Kristy SAuthor
Participant
May 23, 2012

Hi Rob,

Thank you for your quick reply.

I do follow you here.   My table that created in PHPMyAdmin is called users.  Yup I am using  $_SESSIONS for the user credentials. On my Registration Form page I do see that a session was created and it looks like this: Sorry for such a long post but wanted to make sure that I am on the right track.

<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "members.php";
  $MM_redirectLoginFailed = "index.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_Post, $Post);
 
  $LoginRS__query=sprintf("SELECT username, password FROM users WHERE username=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  
  $LoginRS = mysql_query($LoginRS__query, $Post) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
   
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>

Went back and created a new recordset but now I am getting an SQL syntax error messsag for all the new combinations,

['MM_Username'] = $loginUsername; and for

= $_SESSIONS['username'];

I have tried both of these:

SELECT username FROM users

WHERE $username = $_SESSIONS['username'];

and tried this too

SELECT username

FROM users

WHERE $username =$_SESSION['MM_Username'] = $loginUsername

Where did I go wrong in the sql statement?

Participating Frequently
May 23, 2012

A few problems:

SELECT username FROM users

WHERE $username = $_SESSIONS['username'];

First, username is the name of the column, not a php variable. You have it preceeded by a $. Next, SESSION should be singular, not plural.