PHP mysql查询忽略POST变量

时间:2014-11-02 07:43:48

标签: javascript php mysql ajax

我试图将vars从js代码移到php,所以我可以进行查询。我确信这些变量对PHP来说很好。

问题是,当我尝试在SQL查询中组合变量时,它会忽略它们而我没有得到任何结果......

以下是代码中有问题的部分:

    $postdata = file_get_contents("php://input");
    $request = json_decode($postdata);

    $gluten = $_POST['gluten'];
    $vegan = $_POST['vegan'];
    $vegetarian = $_POST['vegetarian'];

     $result = $conn->query("SELECT * FROM dishes JOIN restaurants USING (res_id)
                   WHERE (gluten LIKE '$gluten' AND '$vegan' LIKE 0 AND vegetarian LIKE '$vegetarian')");

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:0)

如果你在php文件中正确获得了POST vars,

像这样查询。

$result = $conn->query("SELECT * FROM dishes JOIN restaurants using (res_id) WHERE (gluten LIKE '%".$gluten."%' AND '".$vegan."' LIKE 0 AND vegetarian LIKE '%".$vegetarian."%')");