Reputation: 61
So Basically this is what i want to do , I want to take data from my database and then put that data on a page after the user logs in , however i am havinng problems understanding a way , So here's some sample code for clarity :
//user has logged in:
//fetched data from database to php file
$name = $result['name'] //result being the object after the queried row is fetched
now i want to add this name in lets say a div in my HTML
<div id="name"><!--$name comes here--></div>
So what is the way to do this using JS ? is AJAX the answer?
Upvotes: 0
Views: 45
Reputation: 1033
I guess that you have $name
in the login.php file and the div
is in profile.php. You can use session variables or ajax:
By php: login.php
<?php
session_start();
$_SESSION["name"] = $result['name']
?>
profile.php
<?php
session_start();
?>
<div id="name"><?php echo $_SESSION["name"]; ?></div>
By ajax:
getName.php
$name = $result['name'];
echo $name;
profile.js
$.get("getName.php", function(data, status){
$("#name").append(data);
});
Upvotes: 1