chetankchandak Posted June 7, 2013 Share Posted June 7, 2013 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']; } ?> Link to comment https://forums.phpfreaks.com/topic/278912-variable-in-the-where-caluse-not-working/ Share on other sites More sharing options...
kicken Posted June 7, 2013 Share Posted June 7, 2013 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 $hostt = "{$matches[0]}\n" ; Why are you adding a \n after the value? Do all the value in your database contain a \n at the end also? Link to comment https://forums.phpfreaks.com/topic/278912-variable-in-the-where-caluse-not-working/#findComment-1434758 Share on other sites More sharing options...
chetankchandak Posted June 8, 2013 Author Share Posted June 8, 2013 Thanks a lot, it worked Link to comment https://forums.phpfreaks.com/topic/278912-variable-in-the-where-caluse-not-working/#findComment-1434824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.