2014-06-28 34 views
-1

我有一个php应用程序与php后端,问题是其中一个PHP脚本在本地服务器上完美工作,而在线时它不会产生以下错误:只在远程服务器托管php脚本的错误

Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/malblbic/public_html/webservice/profile.php on line 23

这是我的php代码。

<?php 

/* 
Our "config.inc.php" file connects to database every time we include or require 
it within a php script. Since we want this script to add a new user to our db, 
we will be talking with our database, and therefore, 
let's require the connection to happen: 
*/ 
require("config.inc.php"); 


//initial query 
$username = $_POST['username']; 
    $query = "Select * FROM users; 

//execute query 
try { 
    $stmt = $db->prepare($query); 
    $result = $stmt->execute(); 
} 
catch (PDOException $ex) { 
    $response[‘success’] = 0; 
    $response["message"] = "Database Error!"; 
    die(json_encode($response)); 
} 

// Finally, we can retrieve all of the found rows into an array using fetchAll 
$rows = $stmt->fetchAll(); 


if ($rows) { 
    $response["success"] = 1; 
    $response["message"] = "User Available!"; 
    $response["posts"] = array(); 

    foreach ($rows as $row) { 
     $post    = array(); 

     $post["picture"] = $row["picture"]; 
     $post["username"] = $row["username"]; 

     $post["points"] = $row["points"]; 


     //update our repsonse JSON data 
     array_push($response["posts"], $post); 
    } 

    // echoing JSON response 
    echo json_encode($response); 


} else { 
    $response["success"] = 0; 
    $response["message"] = "No Users Available!"; 
    die(json_encode($response)); 
} 

?> 
+1

除了在智能/弯引号'[ '成功']'(这已经下文提到的,你”在'$ query ='中丢失''''选择* FROM用户;'注意语法突出显示? - 向文件顶部添加错误报告 'error_reporting(E_ALL); ini_set('display_errors',1) ;' –

回答

1

更改反引号经常引用

$response[‘success’] = 0; 

$response['success'] = 0; 
+0

此外,我建议,当php报告特定行上的错误时,请仔细检查该行。 @FuzzyTree在这里发现了明显的问题,如果你看第23行,你可能会注意到这个问题。 –