This question already has an answer here:

EDIT: The problem was fixed. I had to remove all indentation in the file.

I'm trying to return a JSON array from my server but the PHP keeps throwing this error:

[15-Jun-2015 22:46:59 UTC] PHP Parse error: syntax error, unexpected '{' in /home/user/public_html/backend/xstudio/get_all_mods.php on line 10

I've seen many people have problems like this where they're missing a semicolon or something but I just can't find the problem... Here is my code:

<?php

$response = array("success", "message", array()=>"mods");
define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__.'/db_connect.php');
$db = new DB_CONNECT();
$result = mysql_query("SELECT *FROM mods") or die(mysql_error());

if(mysql_num_rows($result) > 0) {
    while($row = mysql_fetch_array($result)) {
        $mod = array();
        $mod["mod_id"] = $row["mod_id"];
        $mod["name"] = $row["name"];
        $mod["author"] = $row["author"];
        $mod["description"] = $row["description"];
        $mod["download"] = $row["download"];
        $mod["picture"] = $row["picture"];
        $mod["created_at"] = $row["created_at"];
        $mod["updated_at"] = $row["updated_at"];
        array_push($response["mods"], $mod);
    }
    $response["success"] = 1;
    echo json_encode($response);
} else {
    $response["success"] = 0;
    $response["message"] = "No mods found";
    echo json_encode($response);
}
?>

Any and all help is appreciated, thanks!

share|improve this question

marked as duplicate by Rizier123 php Jun 15 '15 at 23:10

This question was marked as an exact duplicate of an existing question.

Try while($row == mysql_fetch_array($result))?

= is assignment. == is equal-to.

share|improve this answer
    
Nope, I tried that right after I asked, same result. – Unknown User Jun 15 '15 at 23:07
    
Sorry for the stock response. According to link this link mysql_fetch_array() is deprecated. What version of php are you using? – Mark A. Ropper Jun 15 '15 at 23:14
    
I am using PHP Version 5.5 Though I switched to 5.4 to test it and it still threw the same error. – Unknown User Jun 15 '15 at 23:17
    
If I try to run it on my machine, with most of the code gutted (I have no idea what's in your db, or how you connect to the database), I get no errors. Might I suggest taking a look at db_connect.php to see if there is something wrong there? Also I get a warning of Illegal offset type on line 3. However, word of warning, if I remember correctly using these mysql_ functions can leave you open to security problems like code injection, might be worth taking a look at PDOs – Mark A. Ropper Jun 15 '15 at 23:35
    
Restructuring $response removes the illegal offset type, $response = array("success"=>0, "message"=>"", "mods"=>array());. Don't think I can help any more with this (at least tonight), sorry. Good luck. – Mark A. Ropper Jun 15 '15 at 23:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.