php - Get the value that comes after the ? operator in the URL


I want to get the value that will come after the '?' operator, for example: r u 

I want to get this value "h r u", and to search this key in my database. I've already tried this:


This function is working fine but when I searched these values it prints like this "h%20r%20u" in my database from this query:

$query="SELECT * FROM databasename WHERE colum LIKE'%$link%'";

It will print link this " h%20r%20u no record found " and my database can't find this value. How can i solve my problem?




Check out the urldecode function.




You should, as pointed out, useurldecode($string). For SQL Injections, just escape the value in your query:

$link = mysql_real_escape_string(urldecode($_SERVER["QUERY_STRING"]));
$query="SELECT * FROM databasename WHERE colum LIKE'%$link%'";

if you use mysql or mysqli to make queries. UsePDO::quote instead to escape if you use PDO.

People are also looking for solutions to the problem: PHP PDO Fetch_Assoc not returning correctly


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.