Reputation:
My question is a bit complicated, so don't get mad if I'm simplifying. So, when a user logs in, I take them to a page showing them information about their account. My question is how do I get their ID and display ONLY their account information, not other people's account. Here is some code:
$sql = "SELECT xp, level, coins, stage FROM users";
So, I want to get their ID and basically echo out their XP, level, coins, and stage. Thanks for the help! Really appreciate it.
Upvotes: 0
Views: 44
Reputation: 2984
I recommend you use Prepared statements, this will beef up your security. As per PHP Manual:
<?php
$id = $_SESSION['id'];
$sql = 'SELECT id, xp, level, coins, stage FROM users WHERE id = ? LIMIT 1'
/* create a prepared statement */
if ($stmt = $mysqli->prepare( $sql )) {
/* bind parameters for markers */
$stmt->bind_param("i", $id); # "i" because your id is probably an int
/* execute query */
$stmt->execute();
/* bind result variables */
$stmt->bind_result($district);
/* fetch value */
$stmt->fetch();
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
?>
That will query the database only for the specific record of the current user ID... Note, I do not know how you are storing the id, so I just put in the $_SESSION
variable, just change it to however you do it.
Upvotes: 1