Page 1 of 1

login area

Posted: Mon Apr 06, 2009 6:38 am
by gwolff2005
Hi guys,
I wrote in another topic already what I needed but maybe did not make myself so clear...

I need to create a loginpage with php and mysql(what I have done): My problem now is: AFTER the user logs in, when he types e.g. in his name, what do I have to write (scriptwise) that the name he entered is in that row, where his login name is (so that the database knows that that name belongs to him. And then... what can I do to call up exactly his name, after he logs in the next time.....

Thanks so much!!!!!!

Re: login area

Posted: Tue Apr 07, 2009 10:27 am
by gwolff2005
Here is the code, when he writes but what do I have to add that it is saved in the row of his login data?

<?php require_once('Connections/Login.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO users (name) VALUES (%s)",
GetSQLValueString($_POST['textfield'], "text"));

mysql_select_db($database_Login, $Login);
$Result1 = mysql_query($insertSQL, $Login) or die(mysql_error());
}

mysql_select_db($database_Login, $Login);
$query_Recordset1 = "SELECT users.name FROM users WHERE users.name";
$Recordset1 = mysql_query($query_Recordset1, $Login) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><!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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<form name="form1" action="<?php echo $editFormAction; ?>" method="POST">
<p>
<input type="text" name="textfield" />
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Re: login area

Posted: Tue Apr 07, 2009 10:36 am
by naeem1984
use this code to matching username and password from database and just use echo statement to show username.

Code: Select all

 
$username = $_POST['username'];
$password = $_POST['password'];
$db_query = "select * from login where username='".$username."' and password='".$password."'";
$result = mysql_query($db_query);
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
 
while ($row = mysql_fetch_array($result)) {
$username_db=$row['username'];
$password_db=$row['password'];
 
//echo $row;
 }
//session_register($username);
mysql_free_result($result);
if(isset($username_db) && isset($password_db))
{
    if(($username==$username_db) && ($password==$password_db))
    {
            echo $username_db;  
    }
}           
else
{
    $action = 'login.php';  
    echo "fill the form";
}   
 

Re: login area

Posted: Tue Apr 07, 2009 10:40 am
by naeem1984
my problem is similer to youand i post this topic as "naeem1984".try to help me if u can.

how making login authentication
which authenticate username and password
if username and password authenticate from database then go to next page
otherwise redirect to login page

Re: login area

Posted: Tue Apr 07, 2009 10:41 am
by gwolff2005
Thanks!! Sounds probably strange but where do I have to enter this code? Under the code which I have shown above?
Thanks again!!

Re: login area

Posted: Tue Apr 07, 2009 10:53 am
by gwolff2005
Hey naem. I created an authentication login already. Here is the code. Just change the data (server, etc..) with which program are you working? Dreamweaver?)

<?php require_once('Connections/Login.php'); ?>
<?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 = "intro.html";
$MM_redirectLoginFailed = "login.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_Login, $Login);

$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, $Login) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";

//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 );
}
}
?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
.style3 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
color: #000033;
}
#Layer1 {
position:absolute;
left:179px;
top:68px;
width:473px;
height:119px;
z-index:1;
}
-->
</style>
</head>
<body>
<div id="Layer1">
<form action="<?php echo $loginFormAction; ?>" method="POST" name="form1" id="form1">
<table width="400" border="0" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="100" class="style3">Username:</td>
<td><div align="left">
<input name="username" type="text" class="style3" id="username" />
</div></td>
</tr>
<tr>
<td width="100"><span class="style3">Password:</span></td>
<td><div align="left">
<input name="password" type="password" class="style3" id="password" />
</div></td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td><div align="left">
<input name="Submit" type="submit" class="style3" value="Submit" />
</div></td>
</tr>
</table>
</form>
</div>
<div align="center"></div>
</body>
</html>