<?php
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
//suppose your database user table name is users and there are three collum in table. id,username,password then run the query to login
$login = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
if($login){
$userdata = mysql_fetch_array($login);
$user_id = $userdata['id']; //where id is the unique auto incremented id in your users table for each user
$username = $userdata['username'];
session_start();
$_SESSION['user_id'] = $user_id;
header("Location:myaccount.php");
}else{
echo "username or password is incorrect";
}
//Now go to the myaccount.php and write the following line on top to authnticate that the logged in user can access the page only
if(!isset($_SESSION['user_id'])){
heaer("Location:login.php");
exit();
}
//All the data will be fetched on the basis of $_SESSION['user_id'] and you have to make an additional collum in all tables that will be user_id collum for each user
//Now fetch the data of logged in user only and leave others
$user_id = $_SESSION['user_id'];
$data = mysql_query("SELECT * FROM datatable WHERE user_id='$user_id'");
?>
Bookmarks