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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.