phpmysqlredbean

insert a variable in SELECT statement


I have this code :

$params = $_GET["params"];
print $params;
if ($_SERVER['REQUEST_METHOD'] == "GET") {
--->//$result = R::getAll( 'SELECT $params FROM user');
} elseif  ($_SERVER['REQUEST_METHOD'] == "POST") {

}
echo json_encode($result);

How correctly set a $params variable into my response. I make a request through RedBeanPhP


Solution

  • I think you should use double quotes in order to have the variable value resolved.

    instead of:

    $result = R::getAll( 'SELECT $params FROM user');
    

    Try:

    $result = R::getAll("SELECT $params FROM user");