-1

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;

}
3
  • 2
    You are also missing ending semi-colon ; for $sql and you are using curly quotes /�? instead of standard quotes "/' in $sql and $result Commented Oct 22, 2014 at 4:32
  • 2
    Those funky quotes will put a damper on your day. Commented Oct 22, 2014 at 4:33
  • Something wrong with your quotes. Commented Oct 22, 2014 at 4:33

1 Answer 1

1

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;
    }
?>
Sign up to request clarification or add additional context in comments.

1 Comment

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!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.