php - Can't echo out user data on home page -
this code function
public function getuserdata() { session_start(); $username = $_session['user']; $getdata = $this->db->prepare("select * users username=?"); $getdata->bindparam(1, $username); $getdata->execute(); $row= $getdata->fetch(pdo::fetch_assoc); $email = $row['email']; $user = $row['username']; echo $email. '<br />'; echo $user; } <?php require_once "class/user.php"; echo $user; echo $email; $object = new user(); $object->getuserdata(); ?>
and here home.php, username, , email echo out function, if try echo $email;
on home.php doesn't print. need print out on home page can style output.
already tried starting session on home.php
, still doesn't work, started in getuserdata()
function.
those variables in scope of function itself, if want access information, you'd have return values function.
user.php
public function getuserdata() { session_start(); $username = $_session['user']; $getdata = $this->db->prepare("select * users username=?"); $getdata->bindparam(1, $username); $getdata->execute(); $row= $getdata->fetch(pdo::fetch_assoc); return $row; }
home.php
<?php require_once "class/user.php"; $object = new user(); $userinfo = $object->getuserdata(); echo $userinfo['username'] . '<br>'; echo $userinfo['email];
Comments
Post a Comment