Answer the question
In order to leave comments, you need to log in
How to write php code to check field value in MySql?
In the table tab1, if the group field - the values of this field can be 1 or 2.
How to write the code to check the user correctly. That is, if a user with group 1, this page is available to him, if not, then no)
Answer the question
In order to leave comments, you need to log in
Let's say $var = field from the database. Then
if($var == 1){
что делать если поле = 1 (не знаю как там у вас доступность страницы определяется_
}
elseif ($var == 2){
что делать если поле = 2 (например сделаем редирект и не дадим ему зайти на страницу)
}
else {
что делать в остальных случаях
}
$stmt = $pdo->prepare("SELECT `group` FROM users WHERE id=?");
$stmt->execute([$id]);
$group = $stmt->fetchColumn();
if ($group != 2)
{
throw new NotEnoughPermissionsException();
}
Listen, it's not clear what you need, pure SQL query or SQL query with PHP code?... Write clearly - what do you want!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question