English 中文(简体)
PHP 如果说话跨越多个线,那么这种说法就意味着什么?
原标题:PHP if statement spanning multiple lines?
  • 时间:2011-08-07 14:41:03
  •  标签:
  • php
  • syntax

我曾试图这样做,但我却继续犯以下错误:

if (isset($_POST[ submit ])) {
    if ( isset($_POST[ agree ]) == false  || 
         isset($_POST[ name ] == false    || 
         isset($_POST[ email ] == false   ||  
         isset($_POST[ title ] == false   ||  
         isset($_POST[ program ] == false || 
         isset($_POST[ course ] == false  ||  
         isset($_POST[ file ] == false    ||) {
        echo   <font color="red"> Please complete all required fields </font><br><br>  ;
    }
}

是否有可能在公共卫生和社会福利部中这样做? 这将使我的法典更加可读。

最佳回答

是的,它完全可行,但你最后有一个挂图(> > > > > > > >,没有表达,你又失去了一个封闭式编码()

而且,你也可以这样做。

if (!isset($_POST[ agree ], $_POST[ name ], ...))

if (array_diff(array( agree ,  name , ...), array_keys($_POST)))

Please note though that all this is probably not testing what you want to test. If you have a f或m, all those fields will be set. Unless the user actively manipulates the f或m, all fields will be submitted with the value "" (an empty string), which makes isset return true. You re either looking f或 empty 或 f或 m或e customized tests.

问题回答

乌姆,如果你纠正了母子并离开了最后的<编码>>>>>>> >。 有效 php代码:

if (isset($_POST[ submit ])) {
   if (!isset($_POST[ agree ]) || 
       !isset($_POST[ name ]) || 
       !isset($_POST[ email ]) ||  
       !isset($_POST[ title ]) ||  
       !isset($_POST[ program ]) || 
       !isset($_POST[ course ])  ||  
       !isset($_POST[ file ])
   ) {
       echo  <font color="red">Please complete all required fields</font><br> ;
   }
}

通过这一方式,<代码><font> 要素为,代之以CSS。

这样做是否简单?

foreach(array( submit , agree , name , email , title , program , course , file ) as $value) {
    if(!isset($_POST[$value])) {
        /* insert form incomplete routine here */
        }
    }

几乎所有的您的<代码> 发送<>/代码>都遗漏了结括号。 最后,你还有外事。

注:错误信息非常清楚地表明:

 Parse error: syntax error, unexpected T_IS_EQUAL, expecting  ,  or  )  in ... on line 5




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签