I have made a user login-logout form using sessions. The code that i am using for session is
retailer_login_session.php
<?php
$connection = mysqli_connect("as.com", "as", "as");
$db = mysqli_select_db("as", $connection);
session_start();
$user_check=$_SESSION['login_user'];
$ses_sql=mysqli_query("select * from retailer_signup where id='$user_check'", $connection);
$row = mysqli_fetch_assoc($ses_sql);
$login_session =$row['id'];
$user_firstname = $row['firstname'];
$user_lastname = $row['lastname'];
if(!isset($login_session)){
mysqli_close($connection);
header('Location: index.html');
}
?>
Eg of able for retailer_signup is
id firstname lastname email password
1 f.retailer l.retailer retailer@gmail.com retailer
the home page of the user needs to display a list of items from a table named retailer_add_property
. Along with the list i wish to display the id of the retailer on the users' home page and further save it to the database
Eg of table for retailer_add_property is
id propertyname propertytype retailerid
1 n.property t.property
Code that i have used to display id on the user's profile page is
<div class="form-group">
<label class="col-lg-3 control-label">Retailer Unique ID:</label>
<? echo $login_session;?>
</div>
The php code that helps in inserting the values of form in the database at back end is
<?php
include('retailer_login_session.php');
$con=mysqli_connect("ab.com","ab","ab","ab");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$propertyname = mysqli_real_escape_string($con, $_POST['propertyname']);
$propertytype = mysqli_real_escape_string($con, $_POST['propertytype']);
$sql="INSERT INTO retailer_add_property(propertyname,propertytype,retailerid) VALUES ('$propertyname','$propertytype','$login_session')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
header("Location: index.html");
mysqli_close($con);
?>
My problem is that the value of the id is neither getting displayed nor being stored in the database. Would appreciate some help regarding the problem