E
E
EvgeN_862018-12-07 12:56:27
1C-Bitrix
EvgeN_86, 2018-12-07 12:56:27

How to check for the existence of a record in the database in 1C Bitrix?

Greetings. Guys, tell me why the text from the $disp variable is displayed immediately, but in fact the check works. The same design but works in a normal document. I use this code in Bitrix.

<?
$pol = $_POST['course'];
$gr = $_POST['gr'];
$disp = "В этом году для Вашего года рождения нет диспансеризации.";
$my = $DB->Query("SELECT * FROM b_dispp_2018 WHERE gr='$gr' && pol='$pol'");
$result = $my->Fetch();
        if ($result)  {
echo '<h2 style="color:green">' . $result['inf'] . '</h2>';
    }
    else 
  {
    echo $disp;
  }

?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Gritsuk, 2018-12-08
@winer

1) Read about sql injections. Example
2) If I were you, I would avoid using $DB->Query for queries. It's better to use D7 ORM instead . You describe the table with a class, and then use the data selections via getList or Query if you need a specific query.
Well, as already said, you need to check something more specific. From your description, it is not at all clear what you are trying to do.

A
Ainur Valiev, 2018-12-08
@vaajnur

Check $result more specifically, it's not Javascript for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question