$_POST를 발행하는 경우
한 페이지에 다른 페이지로 제출하는 양식이 있습니다.여기서 입력이mail
꽉 찼습니다.만약 그렇다면 무언가를 하고 채워지지 않았다면 다른 것을 하세요.빈 양식을 보내도 왜 항상 세팅되어 있는지 이해할 수 없습니다.무엇이 부족하거나 잘못되었습니까?
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.php
:
if (isset($_POST["mail"])) {
echo "Yes, mail is set";
} else {
echo "N0, mail is not set";
}
대부분의 양식 입력은 채워지지 않더라도 항상 설정되므로 비어 있는지도 확인해야 합니다.
부터!empty()
는 이미 양쪽 모두에 대해 체크하고 있습니다.다음 항목을 사용할 수 있습니다.
if (!empty($_POST["mail"])) {
echo "Yes, mail is set";
} else {
echo "No, mail is not set";
}
사용하다!empty
대신isset
.isset return true는 다음과 같습니다.$_POST
왜냐면$_POST
어레이는 슈퍼글로벌이며 항상 존재합니다(세트).
또는 더 나은 사용$_SERVER['REQUEST_METHOD'] == 'POST'
var가 존재하고 NULL 이외의 값이 있으면 TRUE를 반환하고 그렇지 않으면 FALSE를 반환합니다.
빈 공간은 설정된 것으로 간주됩니다.모든 null 옵션을 확인하려면 empty()를 사용해야 합니다.
양식을 빈칸으로 보내면$_POST['mail']
계속 전송되지만 값이 비어 있습니다.필드가 비어 있는지 확인하려면 확인해야 합니다.
if(isset($_POST["mail"]) && trim($_POST["mail"]) != "") { .. }
다음과 같이 간단하게 할 수 있습니다.
if($_POST['username'] and $_POST['password']){
$username = $_POST['username'];
$password = $_POST['password'];
}
또는 empty()를 사용합니다.
if(!empty($_POST['username']) and !empty($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
}
입력 텍스트 양식에 다음 속성을 추가합니다.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 (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";
}
?>
이것이 2단계에서 HTML 양식이라고 생각합시다.php
순서 2. 설명
<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 Form Value를 php 변수에 할당할 수 있습니다.이제 Real Escape String을 사용할 수 있습니다.아래가 당신의 데이터여야 합니다.
스텝2_체크php
if(isset($_POST['mail']) && !empty($_POST['mail']))
{
$mail = mysqli_real_escape_string($db, $_POST['mail']);
}
여기서 $db는 데이터베이스 연결입니다.
FORM이 먼저 전송되었는지 확인한 후 필드를 확인합니다.또한 해커들을 방지하기 위해 필드를 삭제해야 합니다.
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" id="SubmitForm" name= "SubmitForm" value="continue"/>
</form>
스텝2_체크:
if (isset($_POST["SubmitForm"]))
{
$Email = sanitize_text_field(stripslashes($_POST["SubmitForm"]));
if(!empty($Email))
echo "Yes, mail is set";
else
echo "N0, mail is not set";
}
}
투고된 질문에 답하기 위해, isset과 empty는 함께 세 가지 조건을 제시합니다.이것은 Javascript에서 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";
}
?>
$-POST 방법: 폼 태그의 POST 방식을 사용하여 데이터를 전달하면 $_POST 어레이를 사용하여 서버 내의 데이터를 검색할 수 있습니다.이 어레이 이름을 사용하여 서버에서 데이터를 가져옵니다.($_POST['이름'])POST 메서드를 사용하여 폼에서 전송된 정보는 다른 사용자가 볼 수 없으며(모든 이름/값은 HTTP 요청 본문에 포함됨), 보내는 정보의 양에는 제한이 없습니다.코드 예:
<html>
<head>
</head>
<body>
<?php
if(isset($_POST['submit']))
{if(isset($_POST['name']) && isset($_POST['roll']))
{echo"<h1>form submitted</h1>";echo"your name is". $_POST['name']."<br>";
echo "your roll number is". $_POST['roll']."<br>";}}
else{?>
<form action="" method="POST">
Name:<input type="text" name="name"><br><br>
Roll:<input type="text" name="roll"><br>
<br><input type="submit" value="submit" name="submit">
</form>
<?php}?>
</body>
</html>
언급URL : https://stackoverflow.com/questions/13045279/if-isset-post
'programing' 카테고리의 다른 글
PHP의 echo, print, print_r의 차이점은 무엇입니까? (0) | 2022.12.11 |
---|---|
백틱과 아포스트로피의 큰 차이점은 무엇입니까? (0) | 2022.12.11 |
디렉터리에서 필터링된 파일 목록 가져오기 (0) | 2022.12.11 |
MariaDB Galera 클러스터 설정 문제 (0) | 2022.12.11 |
Python 변수의 유형을 확인하는 가장 좋은(자동) 방법은 무엇입니까? (0) | 2022.12.11 |