chetankchandak Posted June 7, 2013 Share Posted June 7, 2013 (edited) 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']; } ?> Edited June 7, 2013 by chetankchandak Quote 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? Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.