Thandi Ngamu Thandi Ngamu - 21 days ago 5
PHP Question

Issue with PHP Like query

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

Answer

I guess you have typo

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