How to make a check for email if there is no email in the database so that "email was not found in the database", and if there was an email in the database so that password recovery was sent to email

Here is the code that checks:

elseif ($a=get_sql_row('profile',"rm='0' and name='email' and value='$id'")) { $error="в базе не найден e-mail"; } 

Well, it displays "e-mail not found in the database" when the email is in the database, and when there is no email in the database, the code sends a password recovery email

  • Help me write the code correctly - wolf123
  • one
    Can change sign = to ==? - atnartur

3 answers 3

In the mind: think through the logic before writing code. For example, as one of the options, if you build a bike, then do it like this:

 class UserInputException extends Exception { } ... try { ... $profile = get_user_profile($id); if (!$profile) { throw new UserInputException("Пользователь не найден."); } $email = $profile->email; if (!$email) { throw new UserInputException("У пользователя не указан email."); } ... } catch (UserInputException $e) { ... $e->getMessage(); ... } ... 

Or find a library / framework, with ready logic for forms, to write only validation.

In Hindu (or just lazy, if the code is still soon in the trash): do something like this:

 elseif (!($a=get_sql_row('profile',"rm='0' and name='email' and value='$id'"))) { $error="в базе не найден e-mail"; } 

If $a in a boolean context is false, the condition will be met. If not, the result of get_sql_row() will be in $a , but $error will not be set.

  • I will not work through the class in my code, and it’s not in my lazy writing - wolf123 September
 get_sql_row // это что такое? 

More information!

get_sql_row value that checks the string in the database

But somehow in Russian to write? did you write this feature yourself? or call us our psychics?

Well, if you are stupid

 and name='email' and value='$id'" 

replaced by

 and name='$email' and value='$id'" // или какая там у тебя переменная на мыло 
  • and name = '$ email' and value = '$ id' "// does not work either, you understand the elseif code itself ($ a = get_sql_row ('profile'," rm = '0' and name = email and value = '$ id' ")) {$ error =" e-mail not found in the database ";} works like this if there is soap in the database, then it is not found, and if there is no soap, it sends it to the mail), but I need to do vice versa) - wolf123
  • if the values ​​in the database match and name = 'email' and value = '$ id', then the code will say that there is an email in the database and will not miss password recovery, but how to do the opposite, for example, there is an email password recovery password, no email, recovery is not available - wolf123

Well, at least it came to one ... You had

 elseif ($a=get_sql_row('profile',"rm='0' and name='email' and value='$id'")) { $error="в базе не найден e-mail"; } 

that is, if there is soap in the database, then catch the error, so that the sign of logical negation (!), as drdaeman already said, will make the logic true

  • it all earned thanks to all))))) - wolf123