R
R
Roman2015-03-14 14:06:04
PHP
Roman, 2015-03-14 14:06:04

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

3 answer(s)
O
Optimus, 2015-03-14
Pyan @marrk2

Let's say $var = field from the database. Then

if($var == 1){
что делать если поле = 1 (не знаю как там у вас доступность страницы определяется_
}
elseif ($var == 2){
что делать если поле = 2 (например сделаем редирект и не дадим ему зайти на страницу)
}
else {
что делать в остальных случаях
}

F
FanatPHP, 2015-03-14
@FanatPHP

$stmt = $pdo->prepare("SELECT `group` FROM users WHERE id=?");
$stmt->execute([$id]);
$group = $stmt->fetchColumn();
if ($group != 2)
{
    throw new NotEnoughPermissionsException();
}

N
Nikita Makarenko, 2015-03-15
@Dreamer879

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 question

Ask a Question

731 491 924 answers to any question