I have a problem with PHP variables. I am showing username which user id is logged in with $_SESSION['uid'];
.
Like $uid = $_SESSION['uid'];
and I have to get the username with
$data = $Details->UserDetails($uid);
$data_username = $data['username'];
So in the index page shows me <?php echo $data_username;?>
but when i use the $data_username
in the following code it is giving me error.
<?php
include_once ("includes/datas.php");
//session_start(); and $data_username will be come within datas.php
if ($_GET['action'] == "get_all_posts") { get_all_posts($db,$config); }
function get_all_posts($db,$config) {
$sql = "select * from `posts` where ((
to_uname = '".mysqli_real_escape_string($db, $data_username)."' AND
from_uname = '".mysqli_real_escape_string($db,$_GET['client'])."' ) OR (
to_uname = '".mysqli_real_escape_string($db,$_GET['client'])."' AND
from_uname = '".mysqli_real_escape_string($db,$data_username)."' )) order by post_id DESC ";
}
?>
I am getting Notice: Undefined variable: data_username What I am missing here anyone can tell me?