2014-04-11 4 views
0

누구든지 이걸 도와 주시겠습니까? php 코드가 잘못 되었나요? "http://phpcodechecker.com/"에 따라PHP를 사용하여 MySQL 데이터베이스에 연결

:

Parse error: syntax error, unexpected '$response' (T_VARIABLE) in your code on line 7 $response["products"] = array();

get_all_products.php

<?php 
$response = array(); 
require_once __DIR__ . '/db_connect.php'; 
$db = new DB_CONNECT(); 
$result = mysql_query("SELECT *FROM products") or die(mysql_error()); 
if (mysql_num_rows($result) > 0) { 
    $response["products"] = array(); 
  
    while ($row = mysql_fetch_array($result)){ 
        $product = array(); 
        $product["pid"] = $row["pid"]; 
        $product["name"] = $row["name"]; 
        $product["price"] = $row["price"]; 
        $product["created_at"] = $row["created_at"]; 
        $product["updated_at"] = $row["updated_at"]; 
        array_push($response["products"], $product); 
    } 
    // success 
    $response["success"] = 1; 
    echo json_encode($response); 
} else { 
    // no products found 
    $response["success"] = 0; 
    $response["message"] = "No products found"; 
    echo json_encode($response); 
} 
?> 
+0

코드를 실행 해 보셨습니까? 그 오류가 발생합니까? –

+0

phpcodechecker를 통해 코드를 실행할 때 오류를 반환하지 않습니다. 시스템에 코드를 아직 배포하지 않으셨습니까? 또한 mysqli_ * 또는 PDO를 사용하면 mysql 라이브러리가 더 이상 사용되지 않으며 공격에 취약하기 때문에 이상적입니다. – Jack

+0

코드가 제대로 작동하며 phpcodechecker에 오류가 없습니다 – gries

답변

관련 문제