I'm self-learning, so pardon my ignorance.
I have 2 SQL tables: user
and product
, both tables contain "user_id"
fields.
I have successfully created a login system that uses email and password fields from the first table (user).
I want to show specific information from the "product" table to the logged-in user. This information should be identified from the user_id field. (user with user_id of 1 should see the product with user_id of 1
login page has:
<?php
session_start();
$message = "";
require_once('account/pdoconnect.php');
if(isset($_POST["login"])) {
if (empty($_POST["email"]) || empty($_POST["password"])) {
$message = '<label>All fields are required</label>';
}
else {
$query = "SELECT * FROM user WHERE email = :email AND password = :password";
$statement = $pdotestconn->prepare($query);
$statement->execute(
array(
'email' => $_POST['email'],
'password' => $_POST['password']
)
);
$count = $statement->rowCount();
if($count > 0) {
$_SESSION["email"] = $_POST["email"];
header("location:account/index.php");
}
else {
$message = '<label>Wrong Email or Password</label>';
}
}
}
?>
Index page has:
<?php session_start();
if(!isset($_SESSION["email"]))
{
header("location:../login.php");
exit;
}
?>
<?php
include("pdoconnect.php");
$id = $_GET['user_id'];
$result = $pdotestconn->prepare("SELECT * FROM product inner join user on
user.user_id = product.user_id");
$result->execute(array($id));
$row = $result->fetch(PDO::FETCH_ASSOC);
?>
Where I insert values with:
<?php
echo $row['amount'];
?>
Problem: I get the same value in the first row (with user_id = 2) for every user logged in