MySQL Forums
Forum List  »  PHP

fetch data from database using sessions and php
Posted by: learner learner
Date: September 09, 2014 02:10AM

I have a page that allows the user to login and see their profile page, however i wish that the users should be able to see their details that are saved in the database on their profile page whenever they login successfully.

retailer_login page is:-

<?php
session_start(); // Starting Session

if (isset($_POST['submit'])) {
try {
if (empty($_POST['email']) || empty($_POST['password'])) {
throw new Exception("email or Password is invalid");
} else {

$email = $_POST['email'];
$password = $_POST['password'];
// To protect MySQL injection for Security purpose
email = stripslashes($email);
password = stripslashes($password);
mail = mysql_real_escape_string($email);
password = mysql_real_escape_string($password);
//Etablishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("abc.com", "abc", "abc");
// Selecting Database
$db= mysql_select_db("abc", $connection);
// SQL query to fetch information of registerd users and finds user match.
$query = mysql_query("select * from adminregister where password='$password' AND email='$email'", $connection);
$rows = mysql_num_rows($query);

if ($rows != 1)
throw new Exception("email or Password is invalid");

$_SESSION['login_user'] = $email; // Initializing Session
header("location: retailer_profile.php"); // Redirecting To Other Page
mysql_close($connection); // Closing Connection
}
}
catch (Exception $e) {
$_SESSION['login_error'] = $e->getMessage();
header("Location: index.html");
}
}
?>


retailer_session page is:-

<?php
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("abc.com", "abc", "abc");
// Selecting Database
$db = mysql_select_db("abc", $connection);
session_start();// Starting Session
// Storing Session
$user_check=$_SESSION['login_user'];
// SQL Query To Fetch Complete Information Of User

$ses_sql=mysql_query("select email from retailerregister where email='$user_check'", $connection);
$row = mysql_fetch_assoc($ses_sql);
$login_session =$row['email'];

if(!isset($login_session)){
mysql_close($connection); // Closing Connection
header('Location: index.html'); // Redirecting To Home Page
}
?>

retailer_profile page is:-


<?php
include('retailer_session.php');

?>

<!DOCTYPE >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Welcome to your homepage</title>

<meta name="viewport" content="width=device-width", initial-scale=1.0">
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="css/styles.css" rel="stylesheet" />
<link href="css/carousel.css" rel="stylesheet">
</head>

<body>
<div id="profile">
<div class="navbar navbar-inverse navbar-static-top">
<div class="container">
<a href="#" class = "navbar-brand"> <id="welcome">Welcome : <i><?php echo $login_session; ?></i> </a>

<button class = "navbar-toggle" data-toggle = "collapse" data-target = ".navHeaderCollapse">
<span class = "icon-bar"> </span>
<span class = "icon-bar"> </span>
<span class = "icon-bar"> </span>
</button>

<div class="collapse navbar-collapse navHeaderCollapse">
<ul class = "nav navbar-nav navbar-right">
<li class ="active"> <a href="retailer_profile.php">Home</a></li>
<li> <a href="retailer_logout.php"><id="logout">Log Out</a></li>
</ul>
</div>
</div>
</div>
</div>

<!--<div name="container">

</div>-->

</body>
</html>


Can Anyone please tell me how can we fetch and display specific data of the user profile page

Options: ReplyQuote


Subject
Written By
Posted
fetch data from database using sessions and php
September 09, 2014 02:10AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.