Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

php error
Forgive me first time coding in php. I am trying to export data from drupal to a json file.
After research i should be missing "}] or something but i cannot find it in line 9 or 10.

Line 10 is

$items['message/json'] = array(

The error is:

Parse error: syntax error, unexpected T_VARIABLE in line 10

<?php
/**
* Implementation of hook_menu()
*/

function message_menu(){

$items = array();

$items['message/json'] = array(
    'title' => 'Json callback',
    'page callback' => 'message_json_page',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,

    );

return $items;
}

/**
*json call back
*/
function message_json_page() {

$sql = “SELECT n.nid , n.title as name, b.body_value as message FROM {node} n INNER          JOIN {field_data_body}  b ON n.nid = b.entity.id WHERE n.status = 1 and n.type = :type”

$result = db_query($sql, array(‘:type’ => ‘message’))->fetchAll();

$json_value = json_encode($result);

print $json_value;

}
share|improve this question

closed as off-topic by sectus, Fred -ii-, Ghost, Phil, deceze Oct 22 '14 at 4:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – sectus, Fred -ii-, Ghost, Phil, deceze
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
You are also missing ending semi-colon ; for $sql and you are using curly quotes / instead of standard quotes "/' in $sql and $result – Sean Oct 22 '14 at 4:32
2  
Those funky quotes will put a damper on your day. – Fred -ii- Oct 22 '14 at 4:33
    
Something wrong with your quotes. – sectus Oct 22 '14 at 4:33
up vote 1 down vote accepted

There were some problems with your quotes within the query. I have modified it, please check now.

<?php
    /**
    * Implementation of hook_menu()
    */

    function message_menu(){
    $items = array();
    $items['message/json'] = array(
        'title' => 'Json callback',
        'page callback' => 'message_json_page',
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,
        );

    return $items;
    }

    /**
    *json call back
    */
    function message_json_page() {        
    $sql = "SELECT n.nid , n.title as name, b.body_value as message
                    FROM {node} n
                        INNER JOIN {field_data_body}  b
                            ON n.nid = b.entity.id
                                WHERE n.status = 1 and n.type = :type";
        $result = db_query($sql, array(":type" => "message"))->fetchAll();
        $json_value = json_encode($result);
        print $json_value;
    }
?>
share|improve this answer
1  
Thanks Blank Head I used your code and i can open the page now. but the error on the page is on line 27. I will check my sql database, it looks like i just need to edit were the code is looking. Thanks for the cool help! – cmdace Oct 22 '14 at 20:39

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