解析错误:语法错误,第127行上的C:\ xampp \ htdocs \ searchresults.php中的文件意外结束

时间:2019-06-01 10:48:42

标签: php

对于PHP来说是非常新的东西,必须创建一个结果页面以使用数据库将用户输入显示为表格。显然,从标题来看,我无法在某个位置关闭脚本。第127行是脚本的最后一行,仅此而已。仅供参考,我使用“ Brackets”作为编辑程序。

我已经完成了所有典型的故障排除方法,已经检查了所有的'{'括号,以确保它们都已关闭,等等,但仍然收到相同的错误。据我所知,该错误是脚本最后一部分的结果,在此我尝试使用结果数据创建一个数组并将其显示为表格。我已经做了所有我知道该怎么做的事情,我尝试了一些建议的故障排除方法,但无济于事。如果有人可以帮助我,我将非常感激。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="styles.css">
<title>Vintage Video - Search Results</title>
</head>
<body>    
<h1>Vintage Video - Search Results</h1>   

<?php

    // Check that the form has been submitted
    if ($_POST) {

        //Store the form data in variables
        $form_manufacturer_name = $_POST['manufacturer_name'];
        $form_camera_model = $_POST['camera_model'];
        $form_lowest_price = $_POST['lowest_price'];
        $form_highest_price = $_POST['highest_price'];

        //Check if the radio button data exists
        if (isset($_POST['format'])) {
            $form_format = $_POST ['format'];
    } 
        else {
            $form_format = "";
    }

        //Trim any trailing and leading spaces form the form data
        $form_manufacturer_name = trim ($form_manufacturer_name);
        $form_camera_model = trim ($form_camera_model);
        $form_lowest_price = trim ($form_lowest_price);
        $form_highest_price = trim ($form_highest_price);

        //Open a connection to the database
        $link = mysqli_connect ('localhost', 'student', 'mmst12009',  'assignment3');

        //define an SQL query to retrieve the vintage camera records
        $query = "
        SELECT
        manufacturers.manufacturer_name,
        manufacturers.manufacturer_url,
        manufacturers.manufacturer_id
        cameras.camera_model,
        cameras.camera_format,
        cameras.camera_weight,
        cameras.camera_price,
        FROM manufacturers, cameras
        WHERE cameras.manufacturer_id = manufacturers.manufacturer_id
        ";


        //Restrict the SQL query with an AND clause if a manufacturer name has been supplied
        if ($form_manufacturer_name !=0) {
            $query .= "AND manufacturers.manufacturer_name = $form_manufacturer_name"; 
    }

        //Restrict the SQL query with an AND clause if a format type has been selected
        if ($form_format !="") {
            $query .= "AND cameras.camera_format = $form_format";
    }

        //Run query and store the results
        $result = mysqli_query ($link, $query);

        //Get the number of rows in the result set
        $number_of_rows = mysqli_num_rows ($result);

        //Close the connection to the database
        mysqli_close ($link);

        //Exit from the script if no records have been retrieved
        if ($number_of_rows == 0) {
        echo <<<END
            <p>No results found from that information!!! Please use the 'Back Page' button and try again</p>
END;
    }
        else {
        //Display the table's column headings
        echo <<<END
            <p>Search Results are presented below.</p>
            <table border = "1">
            <tr>
              <th>ID Number</th>
              <th>Manufacturer</th>
              <th>Model</th>
              <th>Format</th>
              <th>Weight (grams)</th>
              <th>Price</th>
            </tr>  
END;

            //Assign each record in the results to an array
            while ($row = mysqli_fetch_array ($result)) {

                //Assign each array element to a variable
                $manufacturer_id = $row['manufacturer_id'];
                $manufacturer_name = $row['manufacturer_name'];
                $camera_model = $row['camera_model'];
                $camera_format = $row['camera_format']; 
                $camera_weight = $row['camera_weight'];
                $camera_price = $row['camera_price'];

        //Display a table row for each record
        echo <<<END
            <tr>
              <td>$manufacturer_id</td>
              <td>$manufacturer_name</td>
              <td>$camera_model</td>
              <td>$camera_format</td>
              <td>$camera_weight</td>
              <td>$$camera_price</td>
            </tr>
END;            

    }

        echo "</table>";
 }
}

?>
</body>        
</html>

0 个答案:

没有答案