I have created the following function to return member data. However, I am getting an error when I am trying to return the data. Maybe, my method is wrong. What should be the correct way considering the following details?
function memberData(){
global $pdo;
$stmt = $pdo->prepare("SELECT * FROM members WHERE mem_id = :mem");
$stmt-> bindValue(':mem', userId());
$stmt-> execute();
while($f = $stmt->fetch()) {
$return[] = $f;
}
return $return;
}
$memData = memberData();
Doing print_r($memData) returns array of data as following:
Array
(
[0] => Array
(
[mem_id] => 1
[0] => 1
[mem_name] => Shubham Jha
[1] => Shubham Jha
[mem_email] => [email protected]
[2] => [email protected]
[mem_phone_ext] => +91
[3] => +91
[mem_phone] => 9876543210
[4] => 9876543210
[mem_password] => $2y$10$x5LfvrM8VVH/Rzx9NlCW/uktETYufS8yH4VPN/mcwvpmlBJcbarDe
[5] => $2y$10$x5LfvrM8VVH/Rzx9NlCW/uktETYufS8yH4VPN/mcwvpmlBJcbarDe
[mem_phone_verified] => yes
[6] => yes
[mem_email_verified] => no
[7] => no
[mem_date] => 2020-11-16 08:33:22
[8] => 2020-11-16 08:33:22
)
)
How do I echo data separately? I tried using echo $memData['mem_id']; but that returned an error Notice: Undefined index: mem_id in E:\xampp\htdocs\market\includes\functions.php on line 157