Search code examples
phpmysqlfacebook-messenger-bot

Messenger Platform SQL Database access


I'm having trouble in this, i want to return the value of item_name.

$productnum = "1001";

$mysqli = new mysqli("localhost", "ewconline_db_user", "steve030405", "ewconline_db");
    $result = $mysqli->query("SELECT * FROM `shop_products` WHERE `item_id` = '$productnum' ");
    $row = $result->fetch_assoc();
    $item_name = $row['item_name'];

    $response = "{
                    'recipient':{
                        'id': $senderId
                        },
                    'message':{
                        'text': $item_name
                    }
                }";

it doesn't seem to get the value and sends a reply back to user.

and if i run the sql program on different url. it works perfectly fine.


Solution

  • $mysqli = new mysqli("localhost", "ewconline_db_user", "steve030405", "ewconline_db");
    $result = $mysqli->query("SELECT * FROM `shop_products` WHERE `item_id` = '".$productnum."'");
    $row = $result->fetch_assoc();
    $answer = $row['item_name'];
    
    $response = [
        'recipient' => [ 'id' => $senderId ],
        'message' => [ 'text' => $answer ]
    ];
    

    I have done it like this, and it works.

    and used json_encode($response);