php-windows Digest 27 Jun 2007 19:41:25 -0000 Issue 3269
Topics (messages 28156 through 28158):
PHP MySQL login page won't work
28156 by: Don Denton
28157 by: Don Denton
28158 by: Niel Archer
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
The following is text created by dreamweaver CS3 to login a user. There is
something wrong with it because when I enter the appropriate information
into my fields, I get sent to failed.php instead of home.php (both were
specified by me). I have gone over the code as best I can, but I am not
nearly skilled enough to figure out what the hell the problem is. Does
anybody see anything wrong with this?
_________________
<?php require_once('Connections/connReelBadd.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
$theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ?
mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" :
"NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue :
$theNotDefinedValue;
break;
}
return $theValue;
}
}
?><?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['Login'])) {
$loginUsername=$_POST['Login'];
$password=$_POST['Password'];
$MM_fldUserAuthorization = "numAccessLevel";
$MM_redirectLoginSuccess = "home.php";
$MM_redirectLoginFailed = "failed.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_connReelBadd, $connReelBadd);
$LoginRS__query=sprintf("SELECT txtLogin, txtPassword, numAccessLevel FROM
screennames WHERE txtLogin=%s AND txtPassword=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password,
"text"));
$LoginRS = mysql_query($LoginRS__query, $connReelBadd) or
die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'numAccessLevel');
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="POST" action="<?php echo
$loginFormAction; ?>">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<caption>
Hey, you! Login.
</caption>
<tr>
<th scope="row">Login Name</th>
<td><input type="text" name="Login" id="textfield" /></td>
</tr>
<tr>
<th scope="row">Password</th>
<td><input type="password" name="Password" id="textfield2" /></td>
</tr>
<tr>
<th colspan="2" scope="row"><input type="submit" name="Login"
id="Login" value="Do it." /></th>
</tr>
</table>
</form>
</body>
</html>
________________________________________
Thanks in advance!
~Don
--- End Message ---
--- Begin Message ---
-----Original Message-----
From: Don Denton [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 27, 2007 3:01 AM
To: '[EMAIL PROTECTED]'
Subject: PHP MySQL login page won't work
The following is text created by dreamweaver CS3 to login a user. There is
something wrong with it because when I enter the appropriate information
into my fields, I get sent to failed.php instead of home.php (both were
specified by me). I have gone over the code as best I can, but I am not
nearly skilled enough to figure out what the hell the problem is. Does
anybody see anything wrong with this?
_________________
<?php require_once('Connections/connReelBadd.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
$theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ?
mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" :
"NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue :
$theNotDefinedValue;
break;
}
return $theValue;
}
}
?><?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['Login'])) {
$loginUsername=$_POST['Login'];
$password=$_POST['Password'];
$MM_fldUserAuthorization = "numAccessLevel";
$MM_redirectLoginSuccess = "home.php";
$MM_redirectLoginFailed = "failed.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_connReelBadd, $connReelBadd);
$LoginRS__query=sprintf("SELECT txtLogin, txtPassword, numAccessLevel FROM
screennames WHERE txtLogin=%s AND txtPassword=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password,
"text"));
$LoginRS = mysql_query($LoginRS__query, $connReelBadd) or
die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'numAccessLevel');
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="POST" action="<?php echo
$loginFormAction; ?>">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<caption>
Hey, you! Login.
</caption>
<tr>
<th scope="row">Login Name</th>
<td><input type="text" name="Login" id="textfield" /></td>
</tr>
<tr>
<th scope="row">Password</th>
<td><input type="password" name="Password" id="textfield2" /></td>
</tr>
<tr>
<th colspan="2" scope="row"><input type="submit" name="Login"
id="Login" value="Do it." /></th>
</tr>
</table>
</form>
</body>
</html>
________________________________________
Thanks in advance!
~Don
--- End Message ---
--- Begin Message ---
Hi
Duplicating your post isn't going to get you any more or faster replies.
This list is for PHP matters. IF there was anything wrong with the PHP it
would be a Dreamweaver support issue. However the PHP is fine, messy
but fine.
The problem is in your form. You have two 'Login' input values so only
the second is used, which is the button, not your login name. Hence
every query to the DB is looking for 'Do it!' as the user name and
always fails.
Niel
--- End Message ---