Home  >  Article  >  Backend Development  >  How to use if in php to determine whether the text box is equal to empty

How to use if in php to determine whether the text box is equal to empty

藏色散人
藏色散人Original
2020-07-13 10:33:593867browse

php If is not equal to empty judgment method: first obtain the content of the text box through "$_POST['content'];"; then use "if($content==""){}else{} "method to determine whether the text box content is empty; finally execute the relevant file in the browser.

How to use if in php to determine whether the text box is equal to empty

To determine whether the value of a form element is empty in PHP, you first need to submit the form, and then get the form element based on its name to determine whether it is empty.

Examples are as follows:

<?php
if($_POST[&#39;sub&#39;]){
//获取文本框的内容
$content=$_POST[&#39;content&#39;];
if($content==""){
echo "文本框内容为空!";
}else{
echo "文本框内容不为空!";
}
 
}
 
 
?>
<html>
<head>
<title>演示</title>
</head>
<body>
<form name="form1" action="<?php echo $_SERVER[&#39;PHP_SELF&#39;]; ?>" method="post">
<input type="input" name="content"/>
<input type="submit" name="sub"  value="提交"/>
</form>
 
</body>
</html>

For more related knowledge, please visit PHP Chinese website!

The above is the detailed content of How to use if in php to determine whether the text box is equal to empty. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn