Jump to content

Query Not working?


The Little Guy

Recommended Posts

OK, here is my problem. I have 2 text fields, one for zip code, and one for a business name.

If the user only enters in a zip code, it shows all the businesses in that zip code. If the user leaves the zip code as is, and adds a business in the business field such as: "Dick's Sporting Goods", it won't display that business.

 

If the user keeps the zip code, and instead of "Dick's Sporting Goods" he/she puts "Sporting" it works, and displays that business.

 

Test it: http://publicsize.com/rate_my_business/index1 change the drop down to "Zip Code"

 

Business: Dick's Sporting Goods

Zip Code: 55306

 

<?php
if(isset($_GET['q'])){
	$qQuery = addslashes($_GET['q']);
	$qQuery = explode(" ",$qQuery);
	$qQuery = implode("%",$qQuery);
}
if(isset($_GET['zip'])){
	$zipQuery = addslashes($_GET['zip']);
}
$query = "SELECT * FROM rateMyBusiness WHERE zip = '$zipQuery' ";
if(!empty($_GET['q'])){
	$query .= " AND business LIKE '%$qQuery%' ";
}
$sql = mysqli_query($db,$query)or die(mysqli_error($db));
?>

Link to comment
https://forums.phpfreaks.com/topic/66936-query-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.