Strange behavior of a select field

Good morning,

In a form I have a selection field called food_name.
In this field there is a query like this

SELECT nome_alimento
from alimenti
WHERE (categoria = ‘{Categoria}’ and [glo_dd] and marca=’{marca}’)
order by nome_alimento

Where brand category, as you can see, come from another field while the variable glo_dd is a variable passed by another form

Then on the same field there is a script with another query like this

$check_sql = “SELECT energia_kcal,proteine,lipidi,carboidrati,zuccheri,fibre,sodio,vegetariano,vegano”
. " FROM alimenti"
. " WHERE nome_alimento = ‘" . {alimenti} . "’";
sc_lookup(rs, $check_sql);

if (isset({rs[0][0]})) // Row found
{
{kCal_rif} = {rs[0][0]};
{proteine_rif} = {rs[0][1]};
{lipidi_rif} = {rs[0][2]};
{carbo_rif} = {rs[0][3]};
{zuccheri_rif} = {rs[0][4]};
{fibre_rif} = {rs[0][5]};
{sodio_rif} = {rs[0][6]};
{vegeta_rif} = {rs[0][7]};
{vega_rif} = {rs[0][8]};

}

The problem is this: every now and then the query returns nothing
You have any suggestions
Thank you
Mimmo

In your clause WHERE for your 2 SQL, change the field {ALIMENTI} BY {food_name}