я сейчас на php, так что не пугайтесь, если мой код ужасен. Мне было интересно, если кто-нибудь знал, как правильно написать это заявление?
$query = "SELECT age,smoker,drinker FROM profile WHERE user_id ='".$_SESSION['user_id']."'" ;
мой полный код с двух страниц ниже
<?php
session_start();
$db = mysqli_connect('localhost', 'root', '', 'dbgroup19');
$name = "";
$password = "";
if (isset($_POST['login'])) {
$name = $_POST['name'];
$password = $_POST['password'];
$sql_i = "SELECT user_id FROM users WHERE name = '$name'";
$sql_u = "SELECT * FROM users WHERE name='$name'";
$sql_e = "SELECT * FROM users WHERE password='$password'";
$res_i = mysqli_query($db, $sql_i);
$res_u = mysqli_query($db, $sql_u);
$res_e = mysqli_query($db, $sql_e);
if (mysqli_num_rows($res_u) < 1) {
$name_error = "username doesnt exist";
}
elseif (mysqli_num_rows($res_e) < 1) {
$password_error = "incorrect password";
}
else{
$_SESSION["user_id"] = $user_id;
$_SESSION['name'] = $name;
$_SESSION['password'] = $password;
header("location:displayprofile.php");
}
}
?>
<?php include('editprofileredirect.php');
session_start();
$db = mysqli_connect('localhost', 'root', '', 'dbgroup19');
$user_id = $_SESSION["user_id"];
$query = "SELECT age,smoker,drinker FROM profile WHERE user_id ='".$_SESSION['user_id']."'" ;
$results = mysqli_query($db, $query);
?>
<!DOCTYPE html>
<html>
<head>
<title>Display all records from Database</title>
</head>
<body>
<h2>Employee Details</h2>
<table border="2">
<tr>
<td>Sr.No.</td>
<td>Full Name</td>
<td>Age</td>
</tr>
<?php
while($data = mysqli_fetch_array($results))
{
?>
<tr>
<td><?php echo $data['age']; ?></td>
<td><?php echo $data['smoker']; ?></td>
<td><?php echo $data['drinker']; ?></td>
</tr>
<?php
}
?>
</table>
<br>
<form method="post" action="editprofileredirect.php" id="redirect_form">
<button type="submit" name="editprofile" id="edit_btn">add to or edit profile</button>
</form>
</body>
</html>