Jump to content

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


?>
Edited by chetankchandak

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.