Question: I have requirement of getting data from database having column as below:

```
id int(11) PK 
quarter varchar(45) 
year int(11)

```

Quarter can take value of yearly quarter as String e.x. `Q1` , `Q2` , `Q3`, `Q4`.
Year can take value from 2011 to 2014.

Requirement:

* User will input range i.e. for Quarter as Q1 and Q3
* User will inout range i.e. for Year as 2011 and 2013.

We have to return the data that is for Quarter in Q1, Q2, Q3 and Year in 2011,2012 and 2013 and ignore others. Likewise user can input any range.

Please help suggest how can I build generic SQL query for getting the result set?

Answer: 
You will get blank output from `mysqli_real_escape_string` if you don't have a database connection open. This will cause PHP to emit the warning:

> 
> mysqli\_real\_escape\_string() expects exactly 2 parameters, 1 given in - on line …
> 
> 
> 

Connect to the database first and pass the link to it as the first argument.

That said, you should generally avoid `mysqli_real_escape_string` in favour of prepared statements with bound parameters.
You need to add the first parameter as the connection object:

```
$cly=$_GET['cly'];
$clyesc=mysqli_real_escape_string($conn, $cly);
echo $clyesc;

```