How to return data from the user who has logged in?

-1

I need someone to help me with the following problem. I want to perform a select on a MySQL database, the select will be done via Web service with PHP returning a Json for my Android app.

What happens, the user types login and password and the app recognizes the user and opens a second screen, in that second screen has a listview and in that listview should contain all the companies of that user, and it is at this point What is the problem? For me to do this I make a select in PHP in the database, however, select returns me all the companies of the database and not only that of the user who has logged in. I tried to save the company code using SESSION in PHP but it did not work, I would like someone to help me, thanks.

Follow the code in PHP:

<?php

SESSION_START();
echo $_SESSION['Cod_Empresa'];
mysql_connect('localhost','','');
mysql_select_db('bd') or die (mysql_error());

$result = mysql_query( "SELECT UC, Instalacao, Nome_Logo FROM Tab_UC where Cod_Empresa ='".$_SESSION['Cod_Empresa']."'") or die('Could not query');
 for($rows = array(); $row = mysql_fetch_object($result); $rows[] = $row);
 {
    echo json_encode($rows);    
 } 



?>
    
asked by anonymous 01.04.2016 / 16:18

1 answer

0

Well, I understand you want to get the companies of a logged in user.

Looking at your query I saw that you have a table Tab_UC , I deduce that it is the table responsible for the registered companies. And in your where Cod_Empresa ='".$_SESSION['Cod_Empresa']."' you're filtering by company code. Should not filter by user ID logged in?

As I see it, this code returns only one company.

    
01.04.2016 / 18:39