to make our project finish, i need to get the data from the user who just log in(only his/her data) but i dont have any idea how, can someone help me...thank you very much! well appreaciated :)

so this is the part where i need to add something so i can get the specific details based on the user.

<?php

session_start();

include "connect.php";

$sql = "SELECT `client_fname`,`client_lname` FROM `client_accounts` WHERE **//i dont know what to put it here, i think the id but i dont know how//**;";

$query = $db->query($sql);

$msg;
$arr;
$i = 0;

if($query->num_rows > 0){
    while ($row = $query->fetch_assoc()){
        $arr[$i]['fname'] = $row['client_fname'];
        $arr[$i]['lname'] = $row['client_lname'];
        $i++;
    }

    $msg['status'] = true;
    $msg['data']  = $arr;

}else {
    $msg['status'] = false;
}

echo json_encode($msg);

?>

The norm is to search the data table for teh users email address as this is considered unique. Upon registration you need to check if a user firstly entered their email address, then check if it exists, if it does it means they are already registered.

Now use this value to return a row for the login page.

You can then also do the following by adding the values to your _SESSION that can be used throughout your form -

$email = emailfield/input_value_here;

$sql = "SELECT * FROM `client_accounts` WHERE client_email ='".$email."'";
$query = $db->query($sql);
$msg;
$arr;
$i = 0;

//Your code below is incorrect as their will be no loop, only one record is returned...
//if($query->num_rows > 0){
    //while ($row = $query->fetch_assoc()){
        //$arr[$i]['fname'] = $row['client_fname'];
        //$arr[$i]['lname'] = $row['client_lname'];
        //$i++;
    //}

$clientid = $query->client_id;
$fname = $query->client_fname;
$lname = $query->client_lname;

$_SESSION['client_id'] = $clientid;
$_SESSION['client_fname'] = $fname;
$_SESSION['client_lname'] = $lname;
commented: *works +0

so here is my final code!

this is my login query code.

<?php

session_start();

include "connect.php";

$email = $_POST['client_email'];    
$pass = $_POST['client_pass'];

$msg = [];

if(empty($email) || empty($pass)){
    $msg['status'] = false;
    $msg['message'] ="Fill in the blank field!";
}else{

$sql = "SELECT * FROM `client_accounts` WHERE `client_email` = '$email' AND `client_pass` = '$pass'";
$query = $db->query($sql);

while ($row = $query->fetch_assoc()){
        $_SESSION['id'] = $row['client_id'];
        $_SESSION['fname'] = $row['client_fname'];
        $_SESSION['lname'] = $row['client_lname'];
    }

    if($query->num_rows > 0){
        $sql = "SELECT `ct_date`,`ct_amount`,`ct_withdraw`, `ct_currentbal` FROM `ct_trans` as ct, `client_accounts` as ca WHERE `ct`.`ct_id`= `ca`.`client_id`  AND `ca`.`client_email` = '$email' AND `ca`.`client_pass` = '$pass';";

        $query = $db->query($sql);

        while ($row = $query->fetch_assoc()){

            $_SESSION['date'] = $row['ct_date'];
            $_SESSION['amount'] = $row['ct_amount'];
            $_SESSION['withdraw'] = $row['ct_withdraw'];
            $_SESSION['currentbal'] = $row['ct_currentbal'];
}

        $msg['status'] = true;
        $msg['message']  = "login Sucessfully";

}else {
        $msg['status'] = false;
        $msg['message'] = "Failed to login";
}

echo json_encode($msg);
}

?>

and this is the php html part,

   <?php

  session_start()

  ?>

 <!DOCTYPE html>
<head>
<title></title>
</head>
<body>

    <?php echo $_SESSION['fname']; ?></h1>

    <?php echo $_SESSION['lname']; ?></h1>

</body>
</html>

thank you very much!
commented: Only a pleasure, please mark the question as solved, thanks. +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.