I'm trying to make a profile page with a few related blanks e.g username, city, country & address. Currently I'm only working on the username. My question is, how do I update the username on the database according to the logged in user's ID. For starter, I have an ID column for every user, their first name, last name, and email. Currently my WHERE clause in the query says WHERE id = 1
and that is why it stores whatever username I input, in row 1. I want to know, how can I store the username according to the logged in user's ID. And yes, only a logged in user can access the profile page I'm working on.
This is my action.php:
<?php
session_start(); //---> start session
require('db.php');
ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$con = mysqli_connect('localhost', 'id1753243_venom', 'roushan123', 'id1753243_gameware_01');
if(!$con)
{
echo 'Not connected to the server';
}
$id = $_SESSION['id'];
if(isset($_POST['username']))
{
$username = $_POST['username'];
$sql = "UPDATE users SET username='".mysqli_real_escape_string($con,$username)."' WHERE id = '.$id.'";
$insert = mysqli_query($con,$sql);
$_SESSION['username'] = $username; //---> this will store username into session variable
}
if(!$insert)
{
echo 'Not inserted';
}
else
{
echo 'Inserted';
}
header("refresh:2; url=user.php");
?>
The above WHERE clause doesn't seem to work either. I'm hopping someone here can help me solve my problem as it's really important for me to do so. Thanks in advance!