Forums
This topic is locked
Login only displays 1st user on database...
Posted 18 Oct 2007 14:49:14
1
has voted
18 Oct 2007 14:49:14 chris jones posted:
I've only just written the site so its not in use just yet.I'm sure this is a problem that has been solved before but I cant seem to find it (2days looking).
I've written the (MySQL)table out and it all seems to be working.
There is a login page and then this redirects to the profiles page.
The problem I'm having is when a user logs in the profile page only displays the 1st entry in the db.
I've put three users in to check and it wont bring up the other users when I log in under their details.
Just a quick run through what I'm doing in DW.
Register.php
Simple Insert Record function eliminating the ID (Primary Key) and the Date fields from the form as these are set to auto_increment and timestamp.
The registration page works fine and I can query the database through MySql interface and all the correct information is available in the correct table.
Login.php
Added the Text Fields. Username and password, changing the text field for password and renaming textfeild and textfield1 to username and password. Added the Submit button.
Then added the login function using the application presets.
Profile.php
Create the Recordset. set it to query the correct database and table. Add the dynamic text to display the correct information about the user eg. Name
When I execute the login page with for instance the 2nd usename on the database it displays the 1st.
I've also tried to filter the ID and username on the profile page and one way displays nothing at all and the other displays the 1st again.
I have also tried to change the number in: $colname_Recordset1 = "1"; to 2 and 3 but this only displays the the relevant number in the ID field. eg If i add a number 2 and log in as the 1st or 3rd user it only displays the 2nd user and same with 3. I have also tried 4 and it displays nothing.
I've even tried to send a dynamic link from the login page to the detail page to send the information about the user so it might display the right username but that stops the page working at all.
Hope someone can help
Replies
Replied 18 Oct 2007 17:46:57
18 Oct 2007 17:46:57 Alan C replied:
sounds like it could be something to do with the SELECT not on the user table not having the correct value in it, try putting an echo statement that shows you the full sql immediately before the database access, it will mess up your page when it runs but you should be able to check whether or not the WHERE clause contains the correct value.
Replied 18 Oct 2007 18:12:08
18 Oct 2007 18:12:08 chris jones replied:
Would it help if I post the code?
The problem is that I have tried so many different ways I'm only going to be able post the simplist.
Is there no simple way of doing this? I'm sure that Dreamweaver wouldnt let this through there fingers
It seems silly to build an interface that would build a master page that can add a profile page automatically and them no adding the interface to add the user profile page after going through the user autentication interface.
I'm on my 3rd day looking for the answer to this. Think I might get a job delivering milk (if they still exist).
The problem is that I have tried so many different ways I'm only going to be able post the simplist.
Is there no simple way of doing this? I'm sure that Dreamweaver wouldnt let this through there fingers
It seems silly to build an interface that would build a master page that can add a profile page automatically and them no adding the interface to add the user profile page after going through the user autentication interface.
I'm on my 3rd day looking for the answer to this. Think I might get a job delivering milk (if they still exist).
Replied 18 Oct 2007 18:34:21
18 Oct 2007 18:34:21 chris jones replied:
I was hoping someone could just post a "click this-click that" instruction....
Code:
RegisterPage.php:
Works Fine <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
LoginPage.php:
<?php require_once('../Connections/tssws.php'); ?>
<?php
// *** Validate request to login to this site.
session_start();
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_register('PrevUrl');
}
if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "detail.php";
$MM_redirectLoginFailed = "error.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_tssws, $tssws);
$LoginRS__query=sprintf("SELECT username, password FROM users WHERE username='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
$LoginRS = mysql_query($LoginRS__query, $tssws) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;
//register the session variables
session_register("MM_Username"
session_register("MM_UserGroup"
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form ACTION="<?php echo $loginFormAction; ?>" name="form1" method="POST">
<table width="30%" border="0" cellspacing="0" cellpadding="0">
<caption align="top">
Please login.
</caption>
<tr>
<td>Username:</td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td> </td>
<td><input name="Login" type="submit" id="Login" value="Log in"></td>
</tr>
</table>
</form>
</body>
</html>
ProfilePage:
<?php require_once('../Connections/tssws.php'); ?>
<?php
$colname_Recordset1 = "1";
if (isset($_GET['username'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['username']);
}
////I've swapped the above ['ID'] and ['username'] around to see if effects the output. Also changed the WHERE statement from ID to username. Only difference is when username is in the WHERE statement, nothing appears on the profile page. All other config make ths 1st user appear.
mysql_select_db($database_tssws, $tssws);
$query_Recordset1 = sprintf("SELECT * FROM users WHERE ID = '%s'", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $tssws) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p><?php echo $row_Recordset1['ID']; ?></p>
<p> <?php echo $row_Recordset1['username']; ?></p>
<p> <?php echo $row_Recordset1['FirstName']; ?> <?php echo $row_Recordset1['Surname']; ?> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Code:
RegisterPage.php:
Works Fine <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
LoginPage.php:
<?php require_once('../Connections/tssws.php'); ?>
<?php
// *** Validate request to login to this site.
session_start();
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_register('PrevUrl');
}
if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "detail.php";
$MM_redirectLoginFailed = "error.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_tssws, $tssws);
$LoginRS__query=sprintf("SELECT username, password FROM users WHERE username='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
$LoginRS = mysql_query($LoginRS__query, $tssws) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;
//register the session variables
session_register("MM_Username"
session_register("MM_UserGroup"
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form ACTION="<?php echo $loginFormAction; ?>" name="form1" method="POST">
<table width="30%" border="0" cellspacing="0" cellpadding="0">
<caption align="top">
Please login.
</caption>
<tr>
<td>Username:</td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td> </td>
<td><input name="Login" type="submit" id="Login" value="Log in"></td>
</tr>
</table>
</form>
</body>
</html>
ProfilePage:
<?php require_once('../Connections/tssws.php'); ?>
<?php
$colname_Recordset1 = "1";
if (isset($_GET['username'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['username']);
}
////I've swapped the above ['ID'] and ['username'] around to see if effects the output. Also changed the WHERE statement from ID to username. Only difference is when username is in the WHERE statement, nothing appears on the profile page. All other config make ths 1st user appear.
mysql_select_db($database_tssws, $tssws);
$query_Recordset1 = sprintf("SELECT * FROM users WHERE ID = '%s'", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $tssws) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p><?php echo $row_Recordset1['ID']; ?></p>
<p> <?php echo $row_Recordset1['username']; ?></p>
<p> <?php echo $row_Recordset1['FirstName']; ?> <?php echo $row_Recordset1['Surname']; ?> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Replied 19 Oct 2007 13:22:34
19 Oct 2007 13:22:34 Alan C replied:
Hi Chris,
It's a fairly tricky job to sort through the DW code, I can see that first section checks the login then redirects to either the error or detail page, that looks fine, the form uses the POST method, which means that the data is passed in the $_POST array, and the code at the top certainly looks at the right array, so that looks sensible. I've not been through it in detail as that will take ages.
the second part, your detail page (profile page) starts like this . . .
<pre id=code><font face=courier size=2 id=code> if (isset($_GET['username'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['username']);
}</font id=code></pre id=code>
that code is looking at the $_GET array, I may be telling you things you already know here, that means that this detail page is expecting to have username and ID passed to it as url parameters, in other words when your master page calls the detail page it should be appending the parameters to the url, something like this . . .
<pre id=code><font face=courier size=2 id=code> www.yourdomain.co.uk/detail.php?username=value1&ID=value2</font id=code></pre id=code>
see this page
livedocs.adobe.com/dreamweaver/8/using/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=34_obta6.htm
I may be wrong here, but I don't see any code in the master page to generate those parameters
Try putting a print statement in like this . . . in the detail page and seeing what output it gives you for different records from the master page
<pre id=code><font face=courier size=2 id=code> mysql_select_db($database_tssws, $tssws);
$query_Recordset1 = sprintf("SELECT * FROM users WHERE ID = '%s'", $colname_Recordset1);
echo 'query was: '.$query_Recordset1.<br />; // show the query on the page
$Recordset1 = mysql_query($query_Recordset1, $tssws) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?></font id=code></pre id=code>
my guess is that it will always show it is looking up the same record because there are no url parameters being passed
Hope that helps
It's a fairly tricky job to sort through the DW code, I can see that first section checks the login then redirects to either the error or detail page, that looks fine, the form uses the POST method, which means that the data is passed in the $_POST array, and the code at the top certainly looks at the right array, so that looks sensible. I've not been through it in detail as that will take ages.
the second part, your detail page (profile page) starts like this . . .
<pre id=code><font face=courier size=2 id=code> if (isset($_GET['username'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['username']);
}</font id=code></pre id=code>
that code is looking at the $_GET array, I may be telling you things you already know here, that means that this detail page is expecting to have username and ID passed to it as url parameters, in other words when your master page calls the detail page it should be appending the parameters to the url, something like this . . .
<pre id=code><font face=courier size=2 id=code> www.yourdomain.co.uk/detail.php?username=value1&ID=value2</font id=code></pre id=code>
see this page
livedocs.adobe.com/dreamweaver/8/using/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=34_obta6.htm
I may be wrong here, but I don't see any code in the master page to generate those parameters
Try putting a print statement in like this . . . in the detail page and seeing what output it gives you for different records from the master page
<pre id=code><font face=courier size=2 id=code> mysql_select_db($database_tssws, $tssws);
$query_Recordset1 = sprintf("SELECT * FROM users WHERE ID = '%s'", $colname_Recordset1);
echo 'query was: '.$query_Recordset1.<br />; // show the query on the page
$Recordset1 = mysql_query($query_Recordset1, $tssws) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?></font id=code></pre id=code>
my guess is that it will always show it is looking up the same record because there are no url parameters being passed
Hope that helps
Replied 22 Oct 2007 14:23:35
22 Oct 2007 14:23:35 chris jones replied:
Is there no "Click and GO" feature or proceedure that I could follow within dreamweaver to get the result I am after or do I need a PHD in PHP to understand what is actualy going on.
Thanks for the advice but I don't see the reason why dreamweaver have given us the application funcntion if it fails to deliver what I would assume was a very common feature when creating dynamic webpages.
Sure the fact that a dynamic page is there for endusers input would sugest that it is open to abuse so there would require this type of authentication. OK, they have produced the login feature, but what good is this is the feature then gives you access to someone elses profiles?
Please excuse me if I seem like I am ranting on but I have been trying to solve this somewhat feeble problem for over a week now and I am getting rather frustraighted.
(To be honest, most of the features available in dreamweaver I have written myself using an eighth of the code. The only reason for using this software if for speed!! (I knowm one week down the line and not even got a simple login page)). ?>
Thanks for the advice but I don't see the reason why dreamweaver have given us the application funcntion if it fails to deliver what I would assume was a very common feature when creating dynamic webpages.
Sure the fact that a dynamic page is there for endusers input would sugest that it is open to abuse so there would require this type of authentication. OK, they have produced the login feature, but what good is this is the feature then gives you access to someone elses profiles?
Please excuse me if I seem like I am ranting on but I have been trying to solve this somewhat feeble problem for over a week now and I am getting rather frustraighted.
(To be honest, most of the features available in dreamweaver I have written myself using an eighth of the code. The only reason for using this software if for speed!! (I knowm one week down the line and not even got a simple login page)). ?>
Replied 23 Oct 2007 12:15:42
23 Oct 2007 12:15:42 Alan C replied:
I have to agree with you that many of the things DW does I don't like, so I too write a lot of things myself, slotting them into the code as necessary. Some of what DW does is really time-saving, unfortunately some of the other things is not that good. I've one project - a hobby one really and I ended up mixing and matching code because the things I needed were just not going to happen in DW.