1

I have a PHP error I cannot seem to fix with this code

$_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);

Apparently it returns an empty companies list, but when I hardcode it like

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%'

I get my my output, so am wondering where am I going wrong? I have another script that does searching and that is how I implemented it

Kir Chou
  • 2,980
  • 1
  • 36
  • 48
Thandi Ngamu
  • 87
  • 1
  • 9
  • i have question with me. if there is no **relationship** between these two tables ? why not you use join them ? – Karthi Nov 19 '16 at 09:53
  • @Karthi I plan on doing that, but for now I want the query to work, if it does them I plan on replacing it with a join – Thandi Ngamu Nov 19 '16 at 09:59
  • Having used error reporting http://php.net/manual/en/function.error-reporting.php would have more than likely avoided this question. – Funk Forty Niner Nov 19 '16 at 15:59

1 Answers1

2

I guess you have typo

bind_param("ss", $transport, $region); // "region", not "regionS"
AlexandrX
  • 806
  • 8
  • 18