Romano
11-24-2010, 07:33 PM
Hi everyone, I'm looking for some direction on how create a dynamic page that is populated based on the username and password from the login screen. I'm knowledgeable in php but can't seem to get a good direction on this.
Here's what my LogIn page looks like (login.php):
<?php
if(isset($_POST["Submit"])) {
$host="localhost";
$username="username";
$password="password";
$db_name="database";
$tbl_name="registered_members";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['username333'];
$mypassword=$_POST['password333'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1)
{
session_register("myusername");
session_register("mypassword");
header("location:success.php");
}
else {
echo "Wrong Username or Password";
}
}
?>
<!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></title>
<link href="CSS.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="banner"></div>
<div class="mainMenu">
<form action="" method="post" name="form">
<table width="605" border="0" cellspacing="4" cellpadding="0">
<tr>
<td width="257" align="right" valign="top">Email:</td>
<td width="336" align="left" valign="top"><label>
<input name="username333" type="text" id="textfield" size="40" maxlength="40" />
</label></td>
</tr>
<tr>
<td align="right" valign="top">Password:</td>
<td align="left" valign="top"><label>
<input name="password333" type="password" id="textfield2" size="20" maxlength="20" />
</label></td>
</tr>
<tr>
<td align="right" valign="top"></td>
<td align="left" valign="top"></td>
</tr>
<tr>
<td align="right"> </td>
<td align="left"><label>
<input type="submit" name="Submit" id="button" value="Log In" />
</label></td>
</tr>
</table>
</form></div>
</body>
</html>
This works fine. What happens is when the user enters his or her username and password correctly, they go to the webpage success.php, which starts with this php code:
<?
session_start();
if(!session_is_registered(myusername)){
header("location:login.php");
}
?>
This also works fine (visitors can't access this page unless they entered a username and password correctly in the login page). So far so good. Are you guys still with me? I know it's a lot of stuff.
In regards to the database, MySQL database has data for every username and password...data such as address, telephone number, and email for example.
So, here's my question. How can I get the success.php page to populate address, telephone number, and email based on the username and password of the visitor who just logged in? I know this seems (and probably is) simple but my mind is at a deadlock.
Here's what my LogIn page looks like (login.php):
<?php
if(isset($_POST["Submit"])) {
$host="localhost";
$username="username";
$password="password";
$db_name="database";
$tbl_name="registered_members";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['username333'];
$mypassword=$_POST['password333'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1)
{
session_register("myusername");
session_register("mypassword");
header("location:success.php");
}
else {
echo "Wrong Username or Password";
}
}
?>
<!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></title>
<link href="CSS.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="banner"></div>
<div class="mainMenu">
<form action="" method="post" name="form">
<table width="605" border="0" cellspacing="4" cellpadding="0">
<tr>
<td width="257" align="right" valign="top">Email:</td>
<td width="336" align="left" valign="top"><label>
<input name="username333" type="text" id="textfield" size="40" maxlength="40" />
</label></td>
</tr>
<tr>
<td align="right" valign="top">Password:</td>
<td align="left" valign="top"><label>
<input name="password333" type="password" id="textfield2" size="20" maxlength="20" />
</label></td>
</tr>
<tr>
<td align="right" valign="top"></td>
<td align="left" valign="top"></td>
</tr>
<tr>
<td align="right"> </td>
<td align="left"><label>
<input type="submit" name="Submit" id="button" value="Log In" />
</label></td>
</tr>
</table>
</form></div>
</body>
</html>
This works fine. What happens is when the user enters his or her username and password correctly, they go to the webpage success.php, which starts with this php code:
<?
session_start();
if(!session_is_registered(myusername)){
header("location:login.php");
}
?>
This also works fine (visitors can't access this page unless they entered a username and password correctly in the login page). So far so good. Are you guys still with me? I know it's a lot of stuff.
In regards to the database, MySQL database has data for every username and password...data such as address, telephone number, and email for example.
So, here's my question. How can I get the success.php page to populate address, telephone number, and email based on the username and password of the visitor who just logged in? I know this seems (and probably is) simple but my mind is at a deadlock.