Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-17-2011, 09:45 PM   PM User | #1
amcf1992
Regular Coder

 
Join Date: Jul 2011
Posts: 114
Thanks: 7
Thanked 0 Times in 0 Posts
amcf1992 is an unknown quantity at this point
Session variable not echoing

Ok well in dologin.php (~process.php), I sessioned. now in acccount.php i cannot echo them:


doLogin.php
PHP Code:
<?php 
session_start
();
include(
"dbsettings.php");  
mysql_connect("$host""$username""$password")or die("cannot connect");   
mysql_select_db("$db_name")or die("cannot select DB");  
   
$username mysql_real_escape_string($_POST['username']);  
$password md5(mysql_real_escape_string($_POST['password']));  

$sql="SELECT * FROM `user` WHERE `username`='{$username}' AND `password`='{$password}'";  
$result=mysql_query($sql);  
   
// do the check  
if($result)  
{  
    if(
mysql_num_rows($result) == 1)  
    {  
        
$_SESSION['username'] = $username;
        
$_SESSION['password'] = $password;
        
$_SESSION['firstname'] = $firstname;
        
$_SESSION['lastname'] = $lastname;
        
$_SESSION['account'] = $account;
           
        
header("location: account.php");  
            exit();  
    }  
    else  
    {  
      echo 
"Wrong username/password.";  
    }  
}  
else  
{  
    echo 
"The query is not true.";  
}  
?>
account.php
PHP Code:
<?php session_start(); ?>  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>Account Dashboard</title>  
</head>  
<body>  
<?php  
include('dbsettings.php');  

$con mysql_connect("$host","$user","$password");  
if (!
$con)  
  {  
  die(
'Could not connect: ' mysql_error());  
  }  

mysql_select_db("$db_name"$con);  
$username$_SESSION['username']; // Editted 

$sql="SELECT * FROM `user` WHERE `username`='{$username}'";  

$result mysql_query("$sql");  

while(
$row mysql_fetch_array($result))  
  {
  echo 
"Welcome, ";  
 
// echo $row['firstname'] . " " . $row['lastname'];  
  
echo"$username";
    echo 
"<br />";
  echo
"$firstname";
    echo 
"<br />";
  echo
"$lastname";
    echo 
"<br />";
  echo
"$account";
    echo 
"<br />";
  echo
"$username";
    echo 
"<br />";
  
  }  
  
mysql_close($con);  
?>  
<a href="logout.php"> Log Out </a>  
</body>  
</html>
amcf1992 is offline   Reply With Quote
Old 09-18-2011, 01:01 PM   PM User | #2
BluePanther
Senior Coder

 
Join Date: Jul 2011
Posts: 1,226
Thanks: 3
Thanked 171 Times in 171 Posts
BluePanther is on a distinguished road
firstly, this is a problem with your php, not your sql.

Based on your previous questions, you're trying to put code together that you don't understand. You'll do better to learn what each bit of your code is doing.

In regards to your current problem, your echo'ing variables that don't exist in your while loop. Your row information is stored in the row array - to access specific row information, you have to use the row array like the line you commented out in the while loop (example: $row['field']).
BluePanther is offline   Reply With Quote
Reply

Bookmarks

Tags
authentication, md5, mysql, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 02:01 PM.


Advertisement
Log in to turn off these ads.