I have used a variable in the WHERE clause i.e. "$hostt", which is not giving the output results. When I directly put the values, it gives me the desired results. Plz help
<?php $con=mysqli_connect("localhost","root","root","dbname"); // Check connection if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } echo $params = $_SERVER['QUERY_STRING']; // get host name from URL preg_match('@^(?:http://)?([^/]+)@i', "$params", $matches); $host = $matches[1]; // get last two segments of host name preg_match('/[^.]+\.[^.]+$/', $host, $matches); echo "domain name is: {$matches[0]}\n"; $hostt = "{$matches[0]}\n" ; // everything works fine till here. $result = mysqli_query($con,"SELECT * FROM main WHERE store = '$hostt'"); while($row = mysqli_fetch_array($result)) { echo $row['prefix'] . "http://www." . $row['store'] . $row['suffix']; } ?>