I am trying to display the unique user who is logged in and then store it into a table in my database for example if I was logged in as James i want to display James' data from the database and store his id into another table.from my understanding the $_SESSION['login_user']; should return the unique users username.
when ever I run I get this error this is the output:
Notice: Undefined index: login_user in C:\xampp\htdocs\bid.php on line 3
Notice: Undefined variable: SESSION in C:\xampp\htdocs\bid.php on line 8 Thank You For Contacting Us
login.php
<?php
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from form
$myusername = mysqli_real_escape_string($conn,$_POST['username']);
$mypassword = mysqli_real_escape_string($conn,$_POST['password']);
$sql = "SELECT customer_id FROM customer WHERE email_adress = '$myusername' and password = '$mypassword'";
$_SESSION['username'] = $myusername
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['customer_id'];
$count = mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count >= 1) {
$_SESSION['login_user'] = $myusername;
header("location: index2.php");
}else {
$error = "Your Login Name or Password is invalid";
}
}
?>
bid.php:
<?php
session_start();
echo $_SESSION['username'];
require 'config.php';
//include "job.php"
$jobid = $_POST['job_id'];
$bid = $_POST['bid'];
bidderid = $SESSION['username']
echo "$jobid";
$query = "INSERT into bid (bid_amount,job_id) VALUES('" . $bid . "','" . $jobid . "')";
$success = $conn->query($query);
if (!$success) {
die("Couldn't enter data: ".$conn->error);
}
echo "Thank You For Contacting Us <br>";
$conn->close();
?>
session.php
<?php
include('config.php');
session_start();
$user_check = $_SESSION['login_user'];
$ses_sql = mysqli_query($conn,"select email_adress from customer where email_adress = '$user_check' ");
$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$login_session = $row['email_adress'];
if(!isset($_SESSION['login_user'])){
header("location:login.php");
}
?>