Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
. . .and in addition to Bregent's point, the second SELECT statement you provided is also not correct. You can't say "WHERE A = B = C.
You might want to echo $LoginRS__query to make sure the variables are set correctly. Echo $loginUsername to make sure it is populated. That's just a common debugging technique.
You are using code written by Dreamweaver. I realize a lot of people let DW write code for them, but I never do, so I'm not the right person to offer help to those who do. I hadn't realized that until you posted your code.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more