简体   繁体   English

即使没有值,函数也会获得值true

[英]functions gets the value true even when there is no value

i am traing to send a mail with php and i wrote this: 我正在训练用php发送邮件,我这样写:

<?php
function title()
{
if(isset($_GET['title']))
{
    return true;
}
else
{
    echo "please write a title!";
    return false;
}
}

function mess()
{
if(isset($_GET['mess']))
{
    return true;
}
else
{
    echo "please write a messege!";
    return false;
}
}

if(mess() && title())
{
    mail("guycohen801@gmail.com", $_GET['title'], $_GET['mess']);
    echo "the mail has bees send!";
}

?>
<form action="ftp_mail.php" method="get">
the title:
<input type="text" name="title"  />
the messege:
<input type="text" name="mess" />
<input type="submit" value="send" />
</form>

but even when i doesn't writing anything on $_GET['mess'] and $_GET['title'] the functions mess() and title() gets the value true. 但是,即使我没有在$_GET['mess']$_GET['title']上写任何东西,函数mess()title()的值也都为true。 please help!! 请帮忙!!

<?php
if(empty($_POST['title']) && empty($_POST['mess']))
{
    echo "please fill all the fields";
} 
else 
{
    $title = str_replace(array("\r","\n"), "", $_POST['title']);
    mail("email", $title, $_GET['mess']);
    echo "the mail has been sent";
}

Note that it have to be POST form, not GET. 请注意,它必须是POST形式,而不是GET。

用这个

if((isset($_GET['mess'])) && ($_GET['mess']!=""))

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

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