[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

mysql query string in link using urlencode

Posted on 2011-04-23
4
Medium Priority
?
578 Views
Last Modified: 2013-12-12
Greetings,

I have a sql query string that looks something like this:

SELECT * FROM listing_table WHERE (price>=0) AND (price<=1000000) AND (area_name='Town')

For paging through the results I have this: $search_url = urlencode($query); and then have a number of number links for page 2,3 4 and next previous and first last, as is pretty standard.

However when I click the next page now I get an error such as this:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'Town\') ORDER BY at line 1

So the ' mark around the search criteria obviously isn't correct.  If I remove that part of the query string so that the search is only based on numerical criteria it works fine.

So my question is how do I properly make this search string useable in a url?

Thanks very much.

Sky
0
Comment
Question by:Schuyler Kuhl
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
Aaron Tomosky earned 2000 total points
ID: 35453748
Nono. Don't put the whole query in the URL. Just put your variables in the URL. Like .com?low=0&high=100000
then in you code $low = $_get['low']
then build the query wrapping all your variables in mysqlrealescapestring.
0
 

Author Comment

by:Schuyler Kuhl
ID: 35453774
Thank you.

Ok I am following you except for the last part about "wrapping all your variables in mysqlrealescapestring."

It is too bad though because I'm pretty sure this used to work.  I guess I will just have to rewrite this part.

Thank you.

0
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 35453803
$query = "select column from table where price >= '".mysql_real_escape_string($low)."' and...

Sorry for not typing the whole thing out. I'm on my phone.
0
 

Author Comment

by:Schuyler Kuhl
ID: 35453814
thanks very much.

Yes I see this is the proper way to do it now.

Thanks I appreciate your help greatly.

Best regards,

Sky
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month20 days, 6 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question