IT

$ _POST로 제공되는 경우

lottoking 2020. 8. 31. 08:08
반응형

$ _POST로 제공되는 경우


한 페이지에 다른 페이지로 변경하는 양식이 있습니다. 거기에서 입력 메일이 채워져 있는지 확인합니다. 여러 가지 일을하십시오. 빈 양식을 보내도 항상 설정되어있어 말하는 이유를 이해하지 못합니다. 무엇이 잘못 되었습니까?

step2.php :

<form name="new user" method="post" action="step2_check.php"> 
    <input type="text" name="mail"/> <br />
    <input type="password" name="password"/><br />
    <input type="submit"  value="continue"/>
</form>

step2_check :

if (isset($_POST["mail"])) {
    echo "Yes, mail is set";    
} else {    
    echo "N0, mail is not set";
}

다음과 같이 변경하십시오.

if (isset($_POST["mail"]) && !empty($_POST["mail"])) {
    echo "Yes, mail is set";    
} else {  
    echo "N0, mail is not set";
}

그래서 $_POST항상 설정되어 있습니다.

당신은 또한 !empty()값이 설정되어 있는지 여부를 이미 확인, 당신은 또한 버전을 사용할 수 있습니다 :

if (!empty($_POST["mail"])) {
    echo "Yes, mail is set";    
} else {  
    echo "N0, mail is not set";
}

사용 !empty대신에 isset. 배열이 수퍼 글로벌이고 항상 존재 하기 $_POST때문에 isset은 true를 반환 $_POST합니다.

또는 더 나은 사용 $_SERVER['REQUEST_METHOD'] == 'POST'


php.net 에서 isset

var가 존재하고 NULL이 아닌 값이 있으면 TRUE를 반환하고 FALSE를 반환합니다.

빈 공간은 세트로 제공됩니다. 모든 null 옵션을 선택하신 후 비어 있으십시오 ().


양식을 비워두면 $ _POST [ 'mail']은 계속 전송 값은 비어 있습니다. 비어 있는지 확인해야합니다.

if(isset($_POST["mail"]) && trim($_POST["mail"]) != "") { .. }

입력 텍스트에 다음 속성을 추가하십시오 required="required".. 양식을 작성하지 사용자가 양식을 양식 할 양식 할 수 없습니다.

새 코드는 다음과 달라집니다.

<form name="new user" method="post" action="step2_check.php"> 
<input type="text" name="mail" required="required"/> <br />
<input type="password" name="password" required="required"/><br />
<input type="submit"  value="continue"/>
if (isset($_POST["mail"])) {
    echo "Yes, mail is set";    
}

다음을 사용할 수 있습니다.

if($_POST['username'] and $_POST['password']){
  $username = $_POST['username'];
  $password = $_POST['password'];
}

또는 빈 () 사용

if(!empty($_POST['username']) and !empty($_POST['password'])){
  $username = $_POST['username'];
  $password = $_POST['password'];
}

사용 !empty()대신에 isset(). isset()의 경우 항상 귀하 진실을 반환 하기 때문 입니다.

if (!empty($_POST["mail"])) {
    echo "Yes, mail is entered";    
} else {  
    echo "No, mail is not entered";
}

아마도 시도해 볼 수 있습니다.

if (isset($_POST['mail']) && ($_POST['mail'] !=0)) { echo "Yes, mail is set"; } else { echo "No, mail is not set"; }


<?php
    if(isset($_POST['mail']) && $_POST['mail']!='') {
        echo "Yes, mail is set";
    }else{
        echo "N0, mail is not set";
    }
?>

게시 된 질문에 답하기 위해 isset과 empty는 세 가지 조건을 제공합니다. 이 자바 펼쳐보기에서 ajax 명령으로 사용할 수 있습니다.

$errMess="Didn't test";   // This message should not show
if(isset($_POST["foo"])){ // does it exist or not
    $foo = $_POST["foo"]; // save $foo from POST made by HTTP request
    if(empty($foo)){      // exist but it's null
        $errMess="Empty"; // #1 Nothing in $foo it's emtpy

    } else {              // exist and has data
        $errMess="None";  // #2 Something in $foo use it now
      }
} else {                  // couldn't find ?foo=dataHere
     $errMess="Missing";  // #3 There's no foo in request data
  }

echo "Was there a problem: ".$errMess."!";

주 시도 할 수 있습니다.

if (isset($_POST["mail"]) !== false) {
    echo "Yes, mail is set";    
}else{  
    echo "N0, mail is not set";
}

<form name="new user" method="post" action="step2_check.php"> 
  <input type="text" name="mail" required="required"/> <br />
  <input type="password" name="password" required="required"/><br />
  <input type="submit"  value="continue"/>
</form>

<?php
if (!empty($_POST["mail"])) {
    echo "Yes, mail is set";    
}else{  
    echo "N0, mail is not set";
}
?>

당신은 시도 할 수 있습니다,

 <?php

     if (isset($_POST["mail"])) {
            echo "Yes, mail is set";    
        }else{  
            echo "N0, mail is not set";
        }
  ?>

이것이 step2.php의 HTML 양식이라고 생각합시다.

step2.php

<form name="new user" method="post" action="step2_check.php"> 
    <input type="text" name="mail"/> <br />
    <input type="password" name="password"/><br />
    <input type="submit"  value="continue"/>
</form>

데이터베이스에 필요하다고 생각하므로 HTML 양식 값을 php 변수에 할당 할 수 있습니다. 이제 Real Escape String을 사용할 수 있으며 아래는

step2_check.php

if(isset($_POST['mail']) && !empty($_POST['mail']))
{
$mail = mysqli_real_escape_string($db, $_POST['mail']);
}

$ db는 데이터베이스 연결입니다.

참고 URL : https://stackoverflow.com/questions/13045279/if-isset-post

반응형