意外的文件结束php

时间:2014-04-01 17:43:22

标签: php

我得到了一个“预期的布尔”错误,但这似乎优先,我不明白为什么文件的结尾是意外的(我对此非常新!)

任何人都可以在广阔的互联网世界中看到我做错了吗?

//this is what's going on

<?php

//connect to the server

$user = 'root';
$pass = '';
$db = 'classicmodels';

//connect to the database

$db = new mysqli ('localhost', $user, $pass, $db) or die ("Can't connect to database, please try again!");

//query the database

{

mysql_select_db("classicmodels");

        $sql = "SELECT * FROM classicmodels";

//display selected results from database

        WHILE($rows = mysql_fetch_array($query)):

        $productCode =$rows['productCode'];
        $productName =$rows['productName'];
        $productLine =$rows['productLine'];
        $productScale =$rows['productScale'];
        $productVendor =$rows['productVendor'];
        $productDescription =$rows['productDescription'];
        $quantityInStock =$rows['quantityInStock'];
        $buyPrice = $rows['buyPrice'];
        $sellingPrice =$rows['sellingPrice'];



        echo "$productName $productDescription $sellingPrice $quantityInStock";





?>

//问题是什么?

我已经在这里待了两个多小时了,我一直得到同样的两个错误,它是“预期的布尔”或“意外结束” - 据我所知,最终就在那里我能看到但显然我忽略了一些明显的东西!

帮帮我,欧比万肯诺比斯。你是我唯一的希望。

2 个答案:

答案 0 :(得分:2)

您似乎错过了while循环的结束。

//this is what's going on

<?php

//connect to the server

$user = 'root';
$pass = '';
$db = 'classicmodels';

//connect to the database

$db = new mysqli ('localhost', $user, $pass, $db) or die ("Can't connect to database, please try again!");

//query the database

{

mysql_select_db("classicmodels");

        $sql = "SELECT * FROM classicmodels";

//display selected results from database

        WHILE($rows = mysql_fetch_array($query)) {
            $productCode =$rows['productCode'];
            $productName =$rows['productName'];
            $productLine =$rows['productLine'];
            $productScale =$rows['productScale'];
            $productVendor =$rows['productVendor'];
            $productDescription =$rows['productDescription'];
            $quantityInStock =$rows['quantityInStock'];
            $buyPrice = $rows['buyPrice'];
            $sellingPrice =$rows['sellingPrice'];

            echo "$productName $productDescription $sellingPrice $quantityInStock";
        }



?>

我建议使用{}代替:,因为您可以更轻松地查看文本块的开始和结束位置。

答案 1 :(得分:0)

关闭你的&#34;而#34;用&#34; endwhile&#34;

 <?php

//connect to the server

$user = 'root';
$pass = '';
$db = 'classicmodels';

//connect to the database

$db = new mysqli ('localhost', $user, $pass, $db) or die ("Can't connect to database, please try again!");

//query the database
mysql_select_db("classicmodels");

        $sql = "SELECT * FROM classicmodels";

//display selected results from database

        WHILE($rows = mysql_fetch_array($query)):

        $productCode =$rows['productCode'];
        $productName =$rows['productName'];
        $productLine =$rows['productLine'];
        $productScale =$rows['productScale'];
        $productVendor =$rows['productVendor'];
        $productDescription =$rows['productDescription'];
        $quantityInStock =$rows['quantityInStock'];
        $buyPrice = $rows['buyPrice'];
        $sellingPrice =$rows['sellingPrice'];



        echo "$productName $productDescription $sellingPrice $quantityInStock";

      endwhile;



?>