I am building a script. But something seems to be not working.
The Where Clause, where I define a variable :
WHERE store = ‘$hostt’
is not working. If replace this variable with the actual value it works.
[php]<?php
$con=mysqli_connect(“localhost”,“root”,“root”,“dbname”);
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Get the string attached to the url eg: if site url is http://yoursite.com/test/link.php?http://goodlife.com/frr.f
// will result in http://goodlife.com/frr.f
$params = $_SERVER[‘QUERY_STRING’];
// displays http://goodlife.com/frr.f
echo $params;
// get host name from URL i.e. goodlife.com
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” ;
echo “
”;
//displays goodlife.com
echo $hostt;
// 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’];
}
// I dont get any result here, but if i replace $hostt in WHERE clause with goodlife.com, it gives me the results
?>[/php]