isset() function is returning true even when item is not set

后端 未结 4 670
独厮守ぢ
独厮守ぢ 2020-12-04 02:42

Here is my code. For some reason, if I submit the form without placing and passwords in, it still creates the database entry. There are some comments scattered throughout th

相关标签:
4条回答
  • 2020-12-04 03:17

    simple solution: if(!empty($_POST['xxx']) == true) almost equals when you use:

    if(isset($_POST['xxx']) == true && $_POST['xxx'] != '')
    

    except: isset() regards 0(string or number) as true, while empty() regards 0 as true.

    0 讨论(0)
  • 2020-12-04 03:21

    Null and/or empty strings are still set if the variable is declared. Try this:

    if(isset($_POST['user_pass']) && $_POST['user_pass'] != "")

    0 讨论(0)
  • 2020-12-04 03:32

    isset checks that the variable is set - in this case it is set to '' (an empty string). Try using empty() as well.

    0 讨论(0)
  • 2020-12-04 03:35

    Check this one too

    if(isset($_POST['user_pass']) && !empty($_POST['user_pass']))
    

    isset() will check that if the POST is set for 'user_pass' & !empty() will check that if the value is empty.

    0 讨论(0)
提交回复
热议问题