PHP问题与查询一样

时间:2016-11-19 09:33:11

标签: php

我有一个PHP错误,我似乎无法修复此代码

$_POST['location'] = 'Northern Province';
$_POST['transport'] = 'transport';

if (isset($_POST['location'])) {
    $region = "%{$_POST['region']}%";
    $transport = "%{$_POST['transport']}%";
    $stmt = $conn->prepare("SELECT users.id, users.email, users.profilePhoto, users.userType, organization.userFk, organization.name, organization.specialization from users, organization WHERE users.id = organization.userFk AND organization.specialization LIKE ? AND users.region LIKE ?");
    $stmt->bind_param("ss", $transport, $regions);
    $stmt->execute();
    $response["transPortCompanies"] = array();
    $stmt->bind_result($id, $email, $profilePhoto, $userType, $userFk, $name, $specialization);

    while($row = $stmt->fetch()) {
        $company = array();
        $company["id"] = $id;
        $company["email"] = $email;  
        $company["profilePhoto"] = $profilePhoto;
        $company["name"] = $name;
        $company["specialization"] = $specialization;
        $response["message"] = "Loaded";
        $response["error"] = FALSE;
        array_push($response["transPortCompanies"], $company);
    }
    echo json_encode($response);

显然它会返回一个空的companies列表,但是当我像

那样硬编码时
SELECT users.id, users.email, users.profilePhoto, users.userType, organization.userFk, organization.name, organization.specialization from users, organization WHERE users.id = organization.userFk AND organization.specialization LIKE '%transport%' AND users.region LIKE '%Northern Province%'

我得到了我的输出,所以我想知道我哪里出错了?我有另一个搜索的脚本,这就是我实现它的方式

1 个答案:

答案 0 :(得分:2)

我猜你有拼写错误

bind_param("ss", $transport, $region); // "region", not "regionS"