Jump to content

Show data for logged in user


scoobybrew

Recommended Posts

I want to show data for logged in user, i am using sessions to login. This is the code i already have:

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");



//this selects everything for the current user, ready to be used in the script below

$result = mysql_query("SELECT id, points, ingame_points, ingame_money, ingame_items FROM members;
WHERE username = $_SESSION['myusername']");

//this function will take the above query and create an array
while($row = mysql_fetch_array($result))
  {

//with the array created above, I can create variables (left) with the outputted array (right)
$points = $row['points'];
$id = $row['id'];
$ingame_points = $row['ingame_points'];
$ingame_money = $row['ingame_money'];
$ingame_items = $row['ingame_items'];
  }

 

 

Help  :-\?

Link to comment
Share on other sites

<?php
  // Connect to server and select database.
  mysql_connect("$host", "$username", "$password")or die("cannot connect");
  mysql_select_db("$db_name")or die("cannot select DB");

  //this selects everything for the current user, ready to be used in the script below

  $query = "SELECT id, points, ingame_points, ingame_money, ingame_items FROM members WHERE username='{$_SESSION['myusername']}' LIMIT 1";

  if($doQuery = mysql_query($query)) {
    if(mysql_num_rows($doQuery)) {
      $user = mysql_fetch_assoc($doQuery);

      print_r($user);

    } else {
      echo 'No result returned for the query: '.$query;
    }

  } else {
    echo 'The following query failed: '.$query;
  }

 

Try the above code, tell me if it is what you're looking for :)

 

Regards, PaulRyan.

Link to comment
Share on other sites

<?php
  // Connect to server and select database.
  mysql_connect("$host", "$username", "$password")or die("cannot connect");
  mysql_select_db("$db_name")or die("cannot select DB");

  //this selects everything for the current user, ready to be used in the script below

  $query = "SELECT id, points, ingame_points, ingame_money, ingame_items FROM members WHERE username='{$_SESSION['myusername']}' LIMIT 1";

  if($doQuery = mysql_query($query)) {
    if(mysql_num_rows($doQuery)) {
      $user = mysql_fetch_assoc($doQuery);

      print_r($user);

    } else {
      echo 'No result returned for the query: '.$query;
    }

  } else {
    echo 'The following query failed: '.$query;
  }

 

Try the above code, tell me if it is what you're looking for :)

 

Regards, PaulRyan.

 

Thanks, but that doesnt work..

it says

No result returned for the query: SELECT id, points, ingame_points, ingame_money, ingame_items FROM members WHERE username='' LIMIT 1

Whats wrong?

Link to comment
Share on other sites

I don't know if that's all the code in case it is, you need to start the session for that page if not the session will be empty

 

add to the top of the page

<?php 
session_start();

Thanks! I added this at the top of the page and it worked :D Thanks alot  ;)

edit: Oh and also, another question, how do i put the values in diffirent places?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.