简体   繁体   English

strlen()不适用于$ _POST

[英]strlen() doesn't work with $_POST

I am using this code in my *.php file 我在*.php文件中使用此代码

$check = $_POST['dati'];

 if (strlen($check) != 0) {
  // calculations
 }
 else {
   echo "contact me at <a href='mailto:myemail'></a>";
 }

The dati inside that POST is the name attribute of an input field. POST中的dati是输入字段的name属性。 If the input has a length = 0, that echo must be displayed. 如果输入的长度= 0,则必须显示该回波。

I have the same code in another part of my server and it works perfectly. 我在我的服务器的另一部分有相同的代码,它完美地工作。 I'm having troubles here because when the length of dati is 0, the script makes the calculations instead of showing the echo. 我在这里遇到麻烦,因为当dati的长度为0时,脚本会进行计算而不是显示回声。

<input name="dati" id="dati" style="width:310px" type="text">

This is the code of the input. 这是输入的代码。 Any ideas? 有任何想法吗?

You code works well as you can see here: http://codepad.org/fCvlokOJ and here http://codepad.org/t2TvFozt 您可以在此处看到代码运行良好: http//codepad.org/fCvlokOJhttp://codepad.org/t2TvFozt

<?php
$_POST['dati']= "text";

if (strlen($_POST['dati']) != 0) {
   echo" calculations";
 }
 else {
   echo "contact me at <a href='mailto:myemail'></a>";
 }

In the following example, if field is left blank, echo'ed message is "sorry". 在以下示例中,如果字段留空,则回显消息为“抱歉”。

If text entered, then Email link appears. 如果输入文本,则会显示电子邮件链接。 TESTED TESTED

<?php

if(isset($_POST['submit']))

$check = $_POST['dati'];

 if (strlen($check) == 0) {

echo "Sorry";

 }
 else {
   echo "Contact me at <a href='mailto:myemail'>LINK</a>";
 }

?>

FORM 形成

<form method="post" action="your_handler.php">

<input name="dati" id="dati" style="width:310px" type="text">

<input type="submit" name="submit" value="Submit">

</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM