0

I have some problem when i try to get data from SQL and save it on excel, i want to download only the data from the login user, from the session.

This is an example of what i want to do:

$query = ("SELECT * FROM tickets_list WHERE UserName = '".$_SESSION['useruid']."'");
$result = mysqli_query($conn, $query);

The top code is not working... what is working is:

$query = ("SELECT * FROM tickets_list");
$result = mysqli_query($conn, $query);

But i don't want to get in the excel file from all the users..

Can anyone please tell me what i do wrong?

Thank you in advance!

  • Hello @Zaron, welcome to Stack Overflow! Does your `UserName` column actually have this combination of letter upper/lower case? And what error is MySQL giving you? – GigiSan Feb 02 '22 at 11:47
  • What does "_is not working_" mean? Blank page? Wrong results? No results? Did you start your session? Is `$_SESSION['useruid']` filled? [How to get the error message in MySQLi?](https://stackoverflow.com/a/22662582/1839439) – brombeer Feb 02 '22 at 12:00

1 Answers1

0

I think your mistake in SQL, You are searching Username by UserId. That's why it shows this.

$query = ("SELECT * FROM tickets_list WHERE UserName 
  ='".$_SESSION['username']."'");
$result = mysqli_query($conn, $query);

Please, check this.

  • Thank you for the reply. I have fix the problem by start the session at the top of the page. –  Feb 02 '22 at 13:56