Jump to content

Variable in the Where caluse not working


chetankchandak

Recommended Posts

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'];
  }


?>

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.