Jump to content

Recommended Posts

	$sql = "SELECT id,username, date1, date2, total 
	FROM datetable WHERE username = '".$_SESSION['uid']['username'] ."'";

Hello again, I ran into problem when trying to pull information for logged in user. I'm trying to display results for current user only who is signed in.

Now I do have session_start(); and my query works if I replace '".$_SESSION['uid']['username'] ."'"; with 'specificusername' but when I run my current query displayed above it returns me all records with username = empty (I have some empty usernames for testing reasons). So that tells me that query cant find unique user name that is logged in. I don't get any errors and query still goes through.

My datetable structure is 

image.png.848c3fad563b1f05c8e2a5de592d2251.png

 

My uid is defined in another document like so and uses another table called "users"

          session_start();
          $_SESSION['id'] = $row['idUsers'];
          $_SESSION['uid'] = $row['uidUsers'];
          $_SESSION['email'] = $row['emailUsers'];
          header("Location: ../member.php?login=success");
          exit();

This query works on another page where it displays logged in username in html document.

<?php echo $_SESSION['uid']; ?> 

 

I have tried many different ways yesterday to modify my request ( WHERE username = $_SESSION['uid'];  WHERE username = '".$_SESSION["uid"]) many other variations, but no matter what never returns logged in user information only empty username records. 

Can anyone see a problem with that query? or is it due to something else I'm missing?

 

Sorry, maybe this goes in MySQL thread not here in PHP page. If someone can, please move it. Thanks.

 

Edited by sfia
comment on where to post this topic
Link to comment
https://forums.phpfreaks.com/topic/310640-pull-records-for-logged-in-user-only/
Share on other sites

<?php
session_start();
$servername = "";
$username = "";
$password = "";
$dbname   = "";
$connect = mysqli_connect($servername, $username, $password,$dbname);
    $sql = "SELECT id,username, date1 
    FROM datetable WHERE username = '".$_SESSION['uid']['username'] ."'";
$result = mysqli_query($connect, $sql);
$json_array = array();
           while($row = mysqli_fetch_assoc($result))
           {
                $json_array[] = [
				$row['id'],
				$row['username'],
				$row['date1']
				$TotalTime
				];

           }
           echo json_encode($json_array); 
?>

Yes, session_start on each page. I played around a little and edit some things, I do get this now when run the var_dump($_SESSION); code. But my json format disappears.

[]
array(4) {
  ["id"]=>
  int(34)
  ["uid"]=>
  string(8) "bostin21"
  ["email"]=>
  string(18) "emaill123@gmail.com"
  ["user"]=>
  NULL
}

If i removed var_dump($_SESSION); than my query runs again.

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.