Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果POST不为空,则显示文本_Javascript_Php_Variables_Post - Fatal编程技术网

Javascript 如果POST不为空,则显示文本

Javascript 如果POST不为空,则显示文本,javascript,php,variables,post,Javascript,Php,Variables,Post,好的,我有这个页面,里面有一些价格和东西。但最后你可以以百分比的形式给折扣 然后通过邮寄将此百分比发送到新页面。在这里,我需要它显示类似“你已经给了50%的折扣”这样的内容 但是如果没有折扣,并且POST中的百分比字段为空,则它不能显示文本 现在我得到了这样的东西 $procent .= $_POST['percent_discount']; $text .= 'You have recived a discountf of'; $test = $text . $procent; 但是

好的,我有这个页面,里面有一些价格和东西。但最后你可以以百分比的形式给折扣

然后通过邮寄将此百分比发送到新页面。在这里,我需要它显示类似“你已经给了50%的折扣”这样的内容

但是如果没有折扣,并且POST中的百分比字段为空,则它不能显示文本

现在我得到了这样的东西

$procent .= $_POST['percent_discount'];



$text .= 'You have recived a discountf of';

$test = $text . $procent;

但是不管发生什么,它都会显示文本。如果百分比是在文章中发送的,您知道如何让它只显示文本和百分比吗?

您需要使用empty()函数查看是否已设置,或者您也可以使用isset()函数


您需要使用empty()函数来查看它是否已被设置,或者您也可以使用isset()

您可以使用
isset()
检查值。如下所示:

if(isset($_POST['percent_discount'])){
    // do something if its set here
}else{
    // do something if its not set
}
为了与其他答案略有不同,您还可以在以下情况下使用速记:

$myString = (isset($_POST['percent_discount']) ? "You received " .$_POST['percent_discount'] . "!" : "We don't like you. No discount for you!");
等等

希望这有帮助!

您可以使用
isset()
检查值。如下所示:

if(isset($_POST['percent_discount'])){
    // do something if its set here
}else{
    // do something if its not set
}
为了与其他答案略有不同,您还可以在以下情况下使用速记:

$myString = (isset($_POST['percent_discount']) ? "You received " .$_POST['percent_discount'] . "!" : "We don't like you. No discount for you!");
等等


希望这有帮助!

在将文本添加到输出之前,使用if语句检查post字段是否为空

if( !empty( $_POST['percent_discount'] ) ) {
    $text .= 'You have recived a discountf of' . $procent;
}
如果post字段始终存在,这将起作用。如果有时可能根本没有设置该字段,您可以使用
isset

if( isset( $_POST['percent_discount'] ) && !empty( $_POST['percent_discount'] ) ) {
    $text .= 'You have recived a discountf of' . $procent;
}
希望有帮助


在将文本添加到输出之前,使用if语句检查post字段是否为空

if( !empty( $_POST['percent_discount'] ) ) {
    $text .= 'You have recived a discountf of' . $procent;
}
如果post字段始终存在,这将起作用。如果有时可能根本没有设置该字段,您可以使用
isset

if( isset( $_POST['percent_discount'] ) && !empty( $_POST['percent_discount'] ) ) {
    $text .= 'You have recived a discountf of' . $procent;
}
希望有帮助


Dan

您必须设置何时打印文本或何时不打印文本的条件

比如说

if(isset($_POST['percent_discount']))
{
    echo 'This is text, it\'ll be shown if the discount is given.';
}
通过使用条件,它仅在给出折扣时显示文本


希望它有帮助:)

你必须设定条件,何时打印文本,何时不打印文本

比如说

if(isset($_POST['percent_discount']))
{
    echo 'This is text, it\'ll be shown if the discount is given.';
}
通过使用条件,它仅在给出折扣时显示文本


希望有帮助:)

使用
isset()
empty()
或三元运算符。早上拉尔夫在附近又是一个可爱的星期二,嗯@Fred ii-?早上山姆!-是的,当然!@JayBlanchard-现在是星期二?!@JayBlanchard所有赌注都在。马已经出局了。有些人早上6点来的更快。使用
isset()
空()
或者是三元运算符。早上拉尔夫在附近又是一个可爱的星期二,呃@Fred ii-?早上山姆!-是的,当然是!@JayBlanchard-今天是星期二?!@JayBlanchard所有赌注都在。马已经出局了。有些人早上6点会来的更快。如果三元运算符都好的话。我真的很喜欢你的速记版本。这就是我需要的,因为我只能通过调用一个变量(它在mPDF中)来显示结果,但对于该变量,它仍然显示“youreceived!”!“如果没有任何折扣的话?试着用!empty()替换isset(),提供三元的、很好的效果。我真的很喜欢你得到的速记版本。这就是我需要的,因为我只能通过调用一个变量(它在mPDF中)来显示结果,但是有了这个变量,它仍然显示“你收到了!“如果没有折扣,请尝试将isset()替换为!empty()虽然此代码片段可以解决问题,但确实有助于提高您的文章质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因。虽然此代码片段可以解决问题,但确实有助于提高您文章的质量。请记住如果您将来为读者回答这个问题,那么这些人可能不知道您的代码建议的原因。