解析错误:语法错误,意外'}',期望第61行的文件结束

时间:2018-02-22 12:02:15

标签: php mysql

我的代码

<?php

// array for JSON response
$response = array();

// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

// check for post data

     // get a product from products table
    $result = mysql_query("SELECT *FROM druglist") ;

        if (mysql_num_rows($result) > 0) {

            $response["DrugList"]= array();
        while($row=mysql_fetch_array($result)){ 
            $DrugList = array();
            $product["Drugs Name"] = $result["Drugs Name"];
            $product["content"] = $result["content"];
            $product["Type"] = $result["Type"];
            $product["Company"] = $result["Company"];
             // success
        array_push($response["DrugList"],$DrugList);
    }
            $response["success"] = 1;
            // echoing JSON response
            echo json_encode($response);
         }else {
            // no product found
            $response["success"] = 0;
            $response["message"] = "No product found";

            // echo no users JSON
            echo json_encode($response);
        }
?>

1 个答案:

答案 0 :(得分:0)

Use below codes:

$DrugList["Drugs Name"] = $result["Drugs Name"];
$DrugList["content"] = $result["content"];
$DrugList["Type"] = $result["Type"];
$DrugList["Company"] = $result["Company"];

instead of 

            $product["Drugs Name"] = $result["Drugs Name"];
            $product["content"] = $result["content"];
            $product["Type"] = $result["Type"];
            $product["Company"] = $result["Company"];