/    Sign up×
Community /Pin to ProfileBookmark

using php code to display mysql database table content with userid

Good day,
Please I need help on how to fetch data table from the database with userid .
userid was concatenated with the database name.
database name concatenated with userid are the names of the tables in the database.
when a user login and want to view its table it will bring the exact table for the user to view.
Bellow is the code.
Thanks

session_start();
//include(‘verified_functions.php’)

/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user ‘root’ with no password) */
$link = mysqli_connect(“localhost”, “root”, “123456”, “mem_acct”);

// Check connection
if($link === false){
die(“ERROR: Could not connect. ” . mysqli_connect_error());
}

// Attempt select query execution
// $sender_id=$_SESSION[“user”];
$sql=”SELECT * FROM mem_acct_
“.$_SESSION[“userid”];
//$sql = “SELECT * FROM mem_acct_01212155”;
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo ‘<div class=” table-responsive”>’;
echo ‘<center><table class=” table table-striped” border=”0″ cellspacing=”10″ cellpadding=”10″ ></center>’;
echo “<b> <center><h1>SAVING ACCOUNT</h1></center> </b> <br> <br>”;

echo “<tr>”;
echo ‘<th style=” text-align: center; “>POSTED DATE</th>’;
echo ‘<th style=” text-align: center; “>PAYMENT DATE</th>’;
echo ‘<th style=” text-align: center; “>DETAILS</th>’;
echo ‘<th style=” text-align: center; “>DEPOSIT</th>’;
echo ‘<th style=” text-align: center; “>WITHDRAWAL</th>’;
echo ‘<th style=” text-align: center; “>BALANCES</th>’;
echo “</tr>”;
while($row = mysqli_fetch_array($result)){
echo ‘<tr style=” text-align: center; “>’;
echo “<td>” . $row[‘date_posted’] . “</td>”;
echo “<td>” . $row[‘payment_date’] . “</td>”;
echo “<td>” . $row[‘details’] . “</td>”;
echo “<td>” . $row[‘deposit’] . “</td>”;
echo “<td>” . $row[‘withdrawal’] . “</td>”;
echo “<td>” . $row[‘balance’] . “</td>”;
echo “</tr>”;
}
echo “</table>”;
echo”</div>”;
// Free result set
mysqli_free_result($result);
} else{
echo “No records matching your query were found.”;
}

} else{
echo “ERROR: Could not able to execute $sql. ” . mysqli_error($link);
}

// Close connection
mysqli_close($link);
?>
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<title>STATEMENT</title>
<meta name = “viewport” content = “width = device-width, initial-scale = 1.0”>
<link rel=”stylesheet” type=”text/css” href=”css/bootstrap.css”>
<link rel=”stylesheet” type=”text/css” href=”js/jquery-ui/jquery-ui.css”>
<link rel=”stylesheet” type=”text/css” href=”js/jquery-ui/jquery-ui.theme.css”>
<link rel=”stylesheet” type=”text/css” href=”mem_reg_style.css”>
<script type=”text/javascript” src=”js/jquery-3.1.1.js”></script>
<script type=”text/javascript” src=”js/jquery-ui.js”></script>
<script type=”text/javascript” src=”js/bootstrap.js”></script>
<style type=”text/css”>

body{ font: 14px sans-serif; }
</style>

</head>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmMar 31.2020 — OK - so you have told us what you want to do (though it is not a good plan) but why are you posting here? Do you have a problem or a question?
Copy linkTweet thisAlerts:
@HarshShahMay 18.2020 — Hello Ogundare4me,

If you want to show logged user data please refer to this site...

[https://www.geeksforgeeks.org/how-to-display-logged-in-user-information-in-php/](url)

[https://www.sitepoint.com/community/t/after-login-then-it-displays-his-personal-data-taken-from-mysql-db/4807/3](url)
×

Success!

Help @ogundare4me spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...