i am making a simple posting system for a flutter app and a requirement is it must save the post as a JSON file i have the log in done and same with the posting but i am trying to include the name of the user that posted the post by qwering for the current user and writing that to the file i have function that successfully can echo the full name of the user but i am un able to store the var in a way that lets me write it to the file
I have tried a couple of basic examples of querying and storing in var but to no success, I have also tried returning the var of the $fullname that I have in my function
this is my function to get the Fullname(this works) :
public function get_fullname($uid){
$sql3="SELECT fullname FROM users WHERE uid = $uid";
$result = mysqli_query($this->db,$sql3);
$user_data = mysqli_fetch_array($result);
return $user_data['fullname'];
}
this is my code to write the json file (works):
$todays_date = date("y-m-d h:i:sa");
$data = array(
'name' => $user_data['fullname'],
'Title' => $Title,
"post" => $Post,
'date'=> $todays_date,
'uid'=> $uid
);
$tittle = $user_data['fullname'] . "_post_on_" . $todays_date . ".json";
function testfun($tittle, $data)
{
$fh = fopen("posts/$tittle", 'w')
or die("error opening output file");
fwrite($fh, json_encode($data,JSON_UNESCAPED_UNICODE));
fclose($fh);
}
if(array_key_exists('submit',$_POST)){
testfun($tittle, $data);
}
the json comes out like this :
name null
Title "post test 1"
post "this is a test"
date "19-04-28 10:47:13pm"
uid "1"
but i need this :
name "CURENT_USER"
Title "post test 1"
post "this is a test"
date "19-04-28 10:47:13pm"
uid "1"