Having problems displaying user data

Hi there,

First post here, but i’m having a real problem.

I’m trying to display some user data on my web page once a user logs in, such as username country and an avatar.

But for some reason, no matter who logs on i get the same user profiles picture and data pop up.

Could you guys have a qucik look through my code and see where i’m going wrong, or if i’ve made a bit of a hash of it.

I’ve stripped away the html just phowing my php.

ok so code from the index.php

[code]<?php
start_session();
?>

<?php include("dbconnect.php"); if (session_is_registered(myusername)) { $query = "SELECT * FROM members"; $result = mysqli_query($cxn,$query) or die ("Couldn't execute query"); $row = mysqli_fetch_assoc($result); echo "

" . "{$row['username']}
" . "{$row['country']}
"; echo "Not {$row['username']}? Logout"; } else { echo ""; echo ""; echo ""; echo "
"; echo "Click here to register"; echo "
"; } ?>[/code]

checklogin.php

[code]<?php
ob_start();
include (“dbconnect.php”);

// Define $myusername and $mypassword
$myusername=$_POST[‘myusername’];
$mypassword=$_POST[‘mypassword’];

$query=“SELECT * FROM members WHERE username=’$myusername’ and pass=’$mypassword’”;
$result=mysqli_query($cxn, $query);
// Mysql_num_row is counting table row
$count=mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file “login_success.php”
session_register(“myusername”);
session_register(“mypassword”);
header(“location:login_success.php”);
}
else {
echo “Wrong Username or Password”;
}
ob_end_flush();
?>
[/code]

login success.php

[code]<?php
session_start();
if(!session_is_registered(myusername))
{
header(“location:index.php”);
}
?>

Login Successful, redirecting you back the homepage now [/code] and finally logout.php

[code]<?php
session_start();
session_destroy();
?>

You are now logged out, redirecting you back the homepage now [/code]

if you can see where i’m going wrong please let me know, it’s annoying me now.

Cheers

Brucie

u r selecting all rows and display the first. u should select only the row with the right username:
[php] $query = ‘SELECT * FROM members WHERE username="’.mysql_escape_string($_SESSION[‘myusername’]).’"’;[/php]

thank you so much, such a quick fix.

Now i can hammer on with the rest of the site.

Much thanks again.

Sponsor our Newsletter | Privacy Policy | Terms of Service