首页 > 解决方案 > 意外标记:关闭 div 标记

问题描述

我有以下代码。当我运行它时,我在控制台中收到一条错误消息,指出有一个意外的标记 - 结束 div 标记。我不确定为什么。当 if 语句返回 false 时,没有问题。

<div class="container text-center">
  <div class="floatLeft">
    <br><br>
    <h2 class="mb-4 text-white"><? echo $recipe ?></h2>
    <h3> <?echo $description ?> </h3> <br>
    <h3 class="mb-4 text-white"><? echo 'Duration: '. $duration ?></h3>
    <?php
    $query800 = $db->prepare("select * from user_cookbook where userID=:userID");
    $dbParams8 = array('userID'=>$thisUser);
    $query800->execute($dbParams8);
    while ($dbRow8 = $query800->fetch(PDO::FETCH_ASSOC)){
        $recipeIDarray[]=$dbRow8['recipeID'];
    }

    if (in_array($recipeID, $recipeIDarray)){
        echo '<button class="btn btn-light btn-xl sr-button" onclick="window.location.href="/editDisplay.php?id='. $recipeID . '">Edit</button>';
    }

    ?>

    </div>

标签: phphtml

解决方案


那是因为你有一个短的结束 div-tag。通过将代码粘贴到 Notepad++ 中并单击每个 div 以查看它是否有闭合对,我花了 2 秒钟的时间来找出答案。只是提醒一下,这样您就知道如何排除 html 标签的问题了 :)


推荐阅读