没有语法错误的PHP脚本将无法完全解析

时间:2018-07-13 00:15:16

标签: php

我一直在个人Web服务器上使用该PHP脚本苦苦挣扎了一段时间。无论我做什么,或者我给HTML表单提供什么输入(此PHP脚本都是该表单的操作页面),我最终都会看到一个页面,如下所示: enter image description here view larger version

下面是我的代码,应该使用与用户查询匹配的标签来获取食谱ID的列表,然后以表格格式向用户显示匹配食谱的快速概览:

    <html>
    <body>
    <title>Recipe Database</title>
    <h1>recipe finder</h1>
    </body>
    </html>
    <?
    $servername = "localhost";
    $username = "root";
    $password = "xxxx";

    $con = mysqli_connect($servername, $username, $password, "recipes");

    if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $tag = $_POST["keyword"];

    $query = mysqli_query($con, "SELECT id FROM recipes WHERE tag1 LIKE '$tag'");
    $query2 = mysqli_query($con, "SELECT id FROM recipes WHERE tag2 LIKE 
   '$tag'");
    $query3 = mysqli_query($con, "SELECT id FROM recipes WHERE tag3 LIKE'$tag'");
    $result = mysqli_fetch_array($query);
    $result2 = mysqli_fetch_array($query2);
    $result3 = mysqli_fetch_array($query3);
    $list = array_merge($result, $result2);
    $list = array_merge($list, $result3);

    if ($list[0] != ""){
    echo "<table>";
    for ($i = 0; $i < count($list); $i++) {
       echo "<tr>";
       $detailquery = mysqli_query($con, "SELECT * FROM recipes WHERE id LIKE 
    \"$list[$i]\"");
       $details = mysqli_fetch_array($detailquery);
       print "<h3>" . $details[1] . "</h3>";
       print "<p>" . $details[2] . " minutes</p>";
       print "<p>" . $details[3] . " servings</p>";
       echo "</tr>";
    }
    echo "</table>";

} else {
    echo "No recipe with that tag was found. Try a different tag.";
}
?>

我在几个不同的在线语法检查器上进行了测试,结果很干净。是的,所有其他PHP脚本在我的服务器上都运行良好。是的,所有其他PHP脚本正在对该数据库以及我服务器上的其他脚本进行读写,没有错误。是的,我确实尝试将主体和html包裹在PHP脚本周围,没有区别。是的,我检查了不成对的引号和撇号,没有。是的,我尝试将各种查询存储在单独的变量中,这不会影响任何内容。

任何帮助将不胜感激,我确实被困在这一方面。谢谢!

1 个答案:

答案 0 :(得分:0)

糟糕,我好像忘记了扩展标签

<?php 

代替没有“ php”的简短代码。我太过疏忽了。