I have an application (Android) where one does the Login and if the user and password is not in the Database you do not enter. Then here you go to fragment
where I charge a recyclerview
with names of people and the problem is that both the login and the SQL statement for recyclerview
I do from login.php and consuldatos.php, and I have to show different names according to the user. Example:
I enter with pepito and he has me show me:
- user 1
- user 2
- user 3
I enter with broken2 and you have to show me:
- user 4
- user 5
- user 6
They will be different people and I have tried with a session to get the username of login.php
and pass it to consultadatos.php
but it does not work well. But if I put in WHERE
manually a username (WHERE usuario='pepito')
works.
Surely you have poorly focused the PHP
, I hope you can help me, I leave you here.
Login.php
$result='';
if(isset($_POST['username']) && isset($_POST['password']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$_SESSION['username'] = $_POST['username'];
$sql = 'SELECT * FROM login WHERE username = :username AND password = :password';
$stmt = $conn->prepare($sql);
$stmt->bindParam(':username', $username, PDO::PARAM_STR);
$stmt->bindParam(':password', $password, PDO::PARAM_STR);
$stmt->execute();
if($stmt->rowCount())
{
$result="true";
}
elseif(!$stmt->rowCount())
{
$result="false";
}
echo $result;
}
?>
Consuldardatos.php
<?php
include 'DatabaseConfig_Apk.php';
session_start();
$professor = $_SESSION['username'];
// Create connection
$conn = new mysqli($HostName, $HostUser, $HostPass, $DatabaseName);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT NomComplet FROM Info WHERE UserProfessor = '$professor' ";
$result = $conn->query($sql);
if ($result->num_rows >0) {
while($row[] = $result->fetch_assoc()) {
$tem = $row;
$json = json_encode($tem);
}
} else {
echo "No Results Found.";
}
echo $json;
$conn->close();
?>
Thanks