[SOLVED] Dispaly User Data Once Logged In

This is a discussion on "[SOLVED] Dispaly User Data Once Logged In" within the PHP Forum section. This forum, and the thread "[SOLVED] Dispaly User Data Once Logged In are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 21st, 2007, 17:36
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Dispaly User Data Once Logged In

The code below loads data from my mysql database into the form on the page, the only problem is i have to type the persons name from the database into the code for the data to display in the form,

what code should i use so that when the user logs in, the data from that user- that is stored in the sql databse is sent to the form and displayed.

I have mentioned before i am not to sharp with Php, so please dont repley to this thread unless you can provide me a example of code, i want to learn & i am learning, but right now people relpying to my posts leaving comments that dont even display any code or advise related to solving the problem are not helping me solve my problem to be honest.

You will find various threads posted by me on the php forum page, you will notice that a little bit of code here & there attached to them would fix the problem and my problem and give me the chance to learn & see how i should do the code in the future, but i appear to be asking to much. I no people are here to help am just unsure why i have been struggling to get it, its obvious am trying learn

My php code with the form:

PHP: Select all

<!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>
<style type="text/css">
<!--
body {
 background-color: #CCCCCC;
}
-->
</style></head>
<body>
<?php

$con 
mysql_connect("localhost","root","longstand1")
  or
  die(
'Damn!, its messing up. MYSQL reckons <pre>' mysql_error() . '</pre>');

mysql_select_db("dblink_system"$con)
  or
  die (
'Oh hell,  its real messin up now. MYSQL reckons <pre>' mysql_error() . '</pre>');
 

$first_name 'Joe'
 
$query "SELECT * FROM accounts WHERE first_name = '$first_name' LIMIT 1"
$result mysql_query($query)
   or
   die (
'More  mysql errors. MYSQL reckons <pre>' mysql_error() . '</pre>');
   

if (!
mysql_num_rows($result)) 
 die (
'Are you sure your name is in the database');

$details mysql_fetch_array($result);
 
mysql_free_result($result);
mysql_close($con);
 
?>
<!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>Accounts</title>
<style type="text/css">
<!--
body {
 background-color: #CCCCCC;
}
.style1 {
 font-family: "Comic Sans MS";
 font-size: 24px;
 color: #FFFFFF;
}
.style2 {
 font-family: Tahoma;
 color: #FFFFFF;
}
-->
</style></head>
<body>
<table width="559" height="235" border="5" cellpadding="0" cellspacing="0">
  <tr>
    <td height="225" valign="top"><form id="form1" name="form1" method="post" action="">
      <table width="547" height="220" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="42" height="29">&nbsp;</td>
          <td width="190">&nbsp;</td>
          <td width="315">&nbsp;</td>
        </tr>
        <tr>
          <td height="66">&nbsp;</td>
          <td><span class="style1">My name is:</span></td>
          <td><input type="text" name="first_name" value="<?php echo isset($details['first_name']) ? $details['first_name'] : ''// check the value is set and write it down?>" />
        </tr>
        <tr>
          <td height="68">&nbsp;</td>
          <td class="style1">My surname Is:</td>
          <td><input type="text" name="last_name" value="<?php echo isset($details['last_name']) ? $details['last_name'] : ''// check the value is set and write it down?>" />
        </tr>
        <tr>
          <td height="19">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td height="19">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
      </table>
        </form>    </td>
  </tr>
</table>
<p class="style2">Accounts Page</p>
</body>
</html>
Its a web design "help" forum, am jus here for help?


Dont no weather you would need it but here is the login form:

PHP: Select all

<?php require_once('Connections/dblink_system.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['user_name'])) {
  
$loginUsername=$_POST['user_name'];
  
$password=$_POST['password'];
  
$MM_fldUserAuthorization "";
  
$MM_redirectLoginSuccess "account.php";
  
$MM_redirectLoginFailed "log_in.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_dblink_system$dblink_system);
  
  
$LoginRS__query=sprintf("SELECT user_name, password FROM accounts WHERE user_name=%s AND password=%s",
    
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
   
  
$LoginRS mysql_query($LoginRS__query$dblink_system) 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=utf-8" />
<title>User Login</title>
<style type="text/css">
<!--
body {
 background-color: #CCCCCC;
}
.style1 {
 color: #FFFFFF;
 font-family: Tahoma;
}
-->
</style></head>
<body>
<table width="380" height="190" border="5" cellpadding="0" cellspacing="0">
  <tr>
    <td width="368" valign="top"><form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction?>">
      <table width="369" height="178" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <th width="137"><div align="right">Username:</div></th>
          <td width="232"><input type="text" name="user_name" id="user_name" /></td>
        </tr>
        <tr>
          <th><div align="right">Password:</div></th>
          <td><input type="text" name="password" id="password" /></td>
        </tr>
        <tr>
          <th><div align="right">Forgot Password?</div></th>
          <td><input type="submit" name="button" id="button" value="Submit" /></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="reset" name="button2" id="button2" value="Reset" /></td>
        </tr>
      </table>
    </form>    </td>
  </tr>
</table>
<p class="style1">Login Form</p>
</body>
</html>
Cheers
Reply With Quote

  #2 (permalink)  
Old Nov 21st, 2007, 18:45
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: Dispaly User Data Once Logged In

I'm not sure how your login system works... What I would suggest is storing the username in a PHP session variable when the user logs in. Then you could replace this line of code:
PHP: Select all

$first_name 'Joe'
with something like this:
PHP: Select all

$first_name $_SESSION['username']; 

Reply With Quote
  #3 (permalink)  
Old Nov 21st, 2007, 20:16
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Dispaly User Data Once Logged In

Sorry mate unsure how it works, could you show me a working example???


Cheers
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql data loads once user login longstand PHP Forum 9 Feb 7th, 2008 07:10
[SOLVED] User Location Monie Classic ASP 3 Jan 8th, 2008 00:55
online image and offline image showing when logged in and logged out Aaron1988 PHP Forum 4 Apr 5th, 2007 17:24
[SOLVED] I need help with data binding Anonymous User JavaScript Forum 1 Mar 16th, 2005 16:04
Filter data based on user (MSSQL) Webforumz Staff Databases 4 Sep 19th, 2003 05:48


All times are GMT. The time now is 02:06.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43