Return only true or false (PHP)

Amr Ali

I have this PHP code which should return only either true or false after running multiple stored functions, but unfortunately it does not work as expected. I firstly check the email validation and return true if valid and false if invalid, then i am doing the same for username.

if($_SERVER['REQUEST_METHOD'] == 'POST') {

// Email is valid
if(checkmail($_POST['email'])) {
    $_SESSION['v_mail'] = $_POST['email'];
    $valid = true;} else { $valid=false; }

// username is valid
if(checkuser($_POST['username'],5,10)) {
    $_SESSION['v_username'] = $_POST['username'];
    $valid=true;} else { $valid=false; }

}

I need to return only False or True after checking both. I know that it is very small trick but i could not get it.

Federico Ponzi

Try this:

if($_SERVER['REQUEST_METHOD'] == 'POST') {

// Email is valid
if(checkmail($_POST['email'])) {
    $_SESSION['v_mail'] = $_POST['email'];
    $valid = true;} else { $valid=false; }

// username is valid
if(checkuser($_POST['username'],5,10)) {
    $_SESSION['v_username'] = $_POST['username'];
    } else { $valid=false; } //and between the last $valid value

}

or again this:

if($_SERVER['REQUEST_METHOD'] == 'POST') {

// Email is valid
if(checkmail($_POST['email'])) {
    $_SESSION['v_mail'] = $_POST['email'];
    $valid = true;} else { 
 $valid=false; return} //exit from the function if valid is false

// username is valid
if(checkuser($_POST['username'],5,10)) {
    $_SESSION['v_username'] = $_POST['username'];
    $valid=true;} else { $valid=false; }

}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Can grep return true/false or are there alternative methods

분류에서Dev

How to check $addToSet return true or false in mongodb?

분류에서Dev

Javascript If else returns either only TRUE or only FALSE

분류에서Dev

PHP OOP checking if a class is returning true or false?

분류에서Dev

PHP OOP checking if a class is returning true or false?

분류에서Dev

PHP returns false but $.post receives as true

분류에서Dev

How to return(true/false) in ternary operators in jQuery/Javascript?

분류에서Dev

Given string will only print when boolean is false, not when true

분류에서Dev

On / Off 버튼-PHP로 True / False 값 반환

분류에서Dev

_.each find value in array return true or false. using underscore js

분류에서Dev

PHP에서 TRUE와 FALSE 상수 정의 사이의 불일치

분류에서Dev

PHP - Does 1 vs true, 0 vs false or verbosity of variable names affect performance?

분류에서Dev

如果所有字段在PHP和MySQL中都不为空,则返回True或False

분류에서Dev

PHP에서 임의의 부울 true / false 가져 오기

분류에서Dev

PHP : [변수]가 [true 또는 false]와 같으면

분류에서Dev

php is_numeric 및 strlen false 일 때도 true 반환

분류에서Dev

getCheckedItemPositions always return false

분류에서Dev

False / True 열 상수

분류에서Dev

None, False, True 확인

분류에서Dev

클래스가 true 또는 false를 반환하는지 확인하는 PHP OOP?

분류에서Dev

값이 true이고 false가 아닌 경우 PHP 표시 변수 'wpautop'

분류에서Dev

PHP : MySQLi-Query가 true 또는 false를 반환하지 않습니까?

분류에서Dev

PHP는 false를 반환하지만 $ .post는 true로 수신합니다.

분류에서Dev

false && (false)? false : true가 true를 반환하는 이유

분류에서Dev

Boolean Function Always Return False

분류에서Dev

write_only = True 및 required = False가 작동하지 않는 django 나머지 프레임 워크 조합

분류에서Dev

MS Access에서 TRUE <FALSE?

분류에서Dev

LINQ Query returns false when it should be true

분류에서Dev

C LibPCRE TRUE / FALSE 문제

Related 관련 기사

  1. 1

    Can grep return true/false or are there alternative methods

  2. 2

    How to check $addToSet return true or false in mongodb?

  3. 3

    Javascript If else returns either only TRUE or only FALSE

  4. 4

    PHP OOP checking if a class is returning true or false?

  5. 5

    PHP OOP checking if a class is returning true or false?

  6. 6

    PHP returns false but $.post receives as true

  7. 7

    How to return(true/false) in ternary operators in jQuery/Javascript?

  8. 8

    Given string will only print when boolean is false, not when true

  9. 9

    On / Off 버튼-PHP로 True / False 값 반환

  10. 10

    _.each find value in array return true or false. using underscore js

  11. 11

    PHP에서 TRUE와 FALSE 상수 정의 사이의 불일치

  12. 12

    PHP - Does 1 vs true, 0 vs false or verbosity of variable names affect performance?

  13. 13

    如果所有字段在PHP和MySQL中都不为空,则返回True或False

  14. 14

    PHP에서 임의의 부울 true / false 가져 오기

  15. 15

    PHP : [변수]가 [true 또는 false]와 같으면

  16. 16

    php is_numeric 및 strlen false 일 때도 true 반환

  17. 17

    getCheckedItemPositions always return false

  18. 18

    False / True 열 상수

  19. 19

    None, False, True 확인

  20. 20

    클래스가 true 또는 false를 반환하는지 확인하는 PHP OOP?

  21. 21

    값이 true이고 false가 아닌 경우 PHP 표시 변수 'wpautop'

  22. 22

    PHP : MySQLi-Query가 true 또는 false를 반환하지 않습니까?

  23. 23

    PHP는 false를 반환하지만 $ .post는 true로 수신합니다.

  24. 24

    false && (false)? false : true가 true를 반환하는 이유

  25. 25

    Boolean Function Always Return False

  26. 26

    write_only = True 및 required = False가 작동하지 않는 django 나머지 프레임 워크 조합

  27. 27

    MS Access에서 TRUE <FALSE?

  28. 28

    LINQ Query returns false when it should be true

  29. 29

    C LibPCRE TRUE / FALSE 문제

뜨겁다태그

보관