【问题标题】:impossible unexpected '{' parse error [closed]不可能的意外'{'解析错误[关闭]
【发布时间】:2012-09-30 05:59:19
【问题描述】:

我不知道在大括号、方括号和分号排成一行后,我能读多少次或数一数。这已经折磨了我好几个小时。任何见解将不胜感激。

该程序在一天中的大部分时间都在工作。当我发布它并且它起作用时,我会看到需要注意的细节。有时对其进行调整会使它崩溃,就像这样。

文本内容无关紧要,因为取出后问题仍然存在。 说是第 98 行。

代码是否正确缩进?我试过了。

ini_set ('display_errors', 1);
error_reporting (E_ALL | E_STRICT);

require ('head_metas.htm');
require ('head_menus.htm');

//bid_handler.php

// get items
$title = trim($_POST['title']);
$img = trim($_POST['img']);
$medium = trim($_POST['medium']);
$size = trim($_POST['size']);
$date = trim($_POST['date']);
$value = trim($_POST['value']);

// visitor info
$visitorF = trim($_POST['visitorF']);
$visitorL = trim($_POST['visitorL']);
$phone = trim($_POST['phone']);
$email1 = trim($_POST['email1']);
$email2 = trim($_POST['email2']);
$validation1 = filter_var($email1, FILTER_VALIDATE_EMAIL);
$validation2 = filter_var($email2, FILTER_VALIDATE_EMAIL);

$bid_value = trim($_POST['bid_value']);

// confirmation mails
$headers = '...';
$to = 'my@email.com, $email1';
$subject = '...';
$message = $visitorF . $visitorL . ' has offered ' . $bid_value . ' for ' . $title . '.\n\nContact information:\nPnone: ' . $phone . '\nemail address: ' . $email1;

$okay = TRUE;
// welcome + image
if ($okay == TRUE)
{
    print "
        <p>
         Luring text and a captivating image
             <br />
             All \" quotes \" are meticulously struck
        </p>
          ";
    $okay = TRUE;
}



// inaccessible entries
if ( 
    (empty($visitorF)) || 
    (empty($visitorL)) || 
    (empty($email1)) || 
    (empty($email2)) || 
    ($email1 != $email2) ||
    ($validation1 == NULL) || 
    ($validation2 == NULL) 
    ) 
{
    print " 
        There were errors.
        ";
    $okay = FALSE;
}

    // everything looks great
    elseif ( 
        ($okay == TRUE) &&
        (is_numeric($bid_value)) && 
        ($bid_value >= $value) &&
        (isset($visitorF)) && 
        (isset($visitorL)) && 
        (isset($email1)) && 
        (isset($email2)) && 
        ($email1 == $email2) &&
        ($validation1 == TRUE) &&
        ($validation2 == TRUE) 
        ) 
    {
        print "
            <p>
              Thank you, your information is as follows:
              <br />
              Info... prints the variables in a stylish fashion
             </p> ";
             $okay = FALSE;
    }

        else ( 
            ($bid_value < $value) || 
            (empty($bid_value)) 
            )
        {
            print "
                <p>
                 However, your bid has not met the minimum reserve for this piece.
                <br />
                 Please enter a numeric value and try again.
                </p>
                 ";
            $okay = FALSE;
        }


require ('footer.html');
?>

【问题讨论】:

  • "代码缩进是否正确?"缩进只是为了让代码更容易阅读。您对else 有一个条件,这是您不能拥有的。
  • else 更改为 elseif

标签: php parse-error


【解决方案1】:

不确定,但我认为问题出在:

 else ( 
        ($bid_value < $value) || 
        (empty($bid_value)) 
        )

您不能在 else 关键字后面加上 (condition)

【讨论】:

【解决方案2】:

错误

    else ( 
        ($bid_value < $value) || 
        (empty($bid_value)) 
        )

您不能在 else 中使用条件,将其替换为 else ifremove condition

【讨论】:

    【解决方案3】:
      else ( 
            ($bid_value < $value) || 
            (empty($bid_value)) 
            )
        {
    

    这是您不能在else 语句中使用条件的错误 if-elsestatemtent 的基本结构是

    if(condition){
         //condition is true
    }else{
         //condition is false
    }
    

    如果你想使用比elseif更多的条件

    if(condition){
    //condition is true
    }elseif(condition){
    //condition is false
    }else{
    }
    

    您正在使用单个 elseif 语句。

    【讨论】:

      【解决方案4】:

      看这里:

          else ( 
              ($bid_value < $value) || 
              (empty($bid_value)) 
              )
          {
      

      现在让我们把它缩小一点:

      else (($bid_value < $value) || (empty($bid_value))) {
      

      那么你就很明显地看到了问题。在else 语句之后,您不只是有一个条件。 PHP 中 else 语句的设计(请参阅PHP.net documentation for the else control structure)使它清除了if 语句的所有可能情况。这使得它无法接受任何条件,因为其他条件不接受的任何内容都会进入else 语句。

      【讨论】:

        猜你喜欢
        • 2011-09-24
        • 2018-01-08
        • 1970-01-01
        • 2014-04-02
        • 2011-10-26
        • 2014-09-02
        • 2014-04-26
        • 2013-10-02
        • 2023-04-09
        相关资源
        最近更新 更多