PHP Displaying user info when logged in
$strSQL = "SELECT * FROM users";
Why that query? if you say you wanted to display only the info about users logged in, you are getting all users without conditions
Do the query for the user who is logged in at the moment, something like
$strSQL = "SELECT * FROM users WHERE username = '".$_SESSION['username']."'";
or somethinbg like this
<?php
session_start(); //Add this
//Also you have to add your connection file before your query
require('db.php');
// SQL query
$strSQL = "SELECT username, email FROM users WHERE user_id = '".$_SESSION['user_id']."'";
// Execute the query (the recordset $rs contains the result)
$rs = mysqli_query($myConnection, $strSQL);
// Loop the recordset $rs
// Each row will be made into an array ($row) using mysqli_fetch_array
while($row = mysqli_fetch_array($rs)) {
// Write the value of the column FirstName (which is now in the array $row)
echo $row['username'] . "<br />";
echo $row['email'] . "<br />";
}
// Close the database connection
mysqli_close($myConnection);
?>
I think it should have to work, tell me if it worked for you
How to display current user details from database in separate page in php
<?php
include 'config.php';
error_reporting(E_ERROR);
session_start();
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$email=$_POST['email'];
$pass=$_POST['pass'];
$phone=$_POST['phone'];
$sex_select=$_POST['sex_select'];
$month=$_POST['month'];
$day=$_POST['day'];
$year=$_POST['year'];
$result = mysql_query("INSERT INTO crop(fname, lname, email, pass, phone,`sex_select`, month,day,year)
VALUES ('$fname', '$lname', '$email', '$pass','$phone','$sex_select', '$month','$day','$year')");
if(mysql_affected_rows()>1)
{
//it will redeirect you to. your any file.
//you can give any file name here.
$_SESSION['fname']=$fname;//you are adding value to the session
$_SESSION['lanme']=$lname; //you are adding value to the session
//Do this for rest of your value
header('Location:Your_File_name.php');
}
if (!$result) {
die(msg(0,"wrong query"));
}
?>
Show specific content based on current user session PHP
If logged in user shouldn't edit other user's posts, then don't show the edit column, then you can do simple if check for the column Edit like below
while ($row_d = mysql_fetch_assoc($check_d)) {
echo "<h1>Post made by: ".$row_d['username']."</h1>";
$check_u = mysql_query("SELECT * FROM topics WHERE topic_creator='".$row_d['username']."'");
while ($row_u = mysql_fetch_assoc($check_u)) {
$id = $row_u['topic_id'];
echo "<tr>";
echo "<td>".$row_u['topic_id']."</td>";
echo "<td><a href='topic.php?id=$id'>".$row_u['topic_name']."<br /></a></td>";
echo "<td>".$row_u['topic_creator']."<br /></td>";
echo "<td>".$row_u['date']."<br /></td>";
// Add if condition here
if($_SESSION['current_logged_in_user_id'] === $row_u['topic_creator_id']) {
echo "<td><a href='edit.php?edit=$id'>Edit</a><br /></td>";
}
echo "</tr>";
}
}
but don't use mysql_* functions. use mysqli or PDOs for security reasons like protecting yourself from sql injection attacks.
Related Topics
Calculate Size in Bytes of Json Payload Including It in the Json Payload in PHP
Php Warning: Mysqli_Connect(): (Hy000/2002): Connection Refused
What Is the Easiest Way to Check If Time Is Set in Datetime Variable
Regex - Exclude "-" Between Numbers
Disable Xampp Redirect Http to Https
Laravel 5.5 Http Error 500 Unable to Handle This Request
How to Convert Jquery Ajax Success Data to a PHP Variable
How to Prevent Multiple Inserts When Submitting a Form in PHP
How Should a Model Be Structured in MVC
Showing All Errors and Warnings
How to Change Value of Select Options Based on Another Select Option Selected
Laravel Eloquent Sum of Multiplied Columns
How to Get Previous Month from Selected Month
Checking Dates If Between Range of Dates in Laravel 5
How to Pass a Number With Forward Slash "/" to Codeigniter Controller Using Ajax
Display Text(Html) Saved in Database Using Ckeditor