PHP - Not Replacing Variable With Data

Hi Guys,

I am getting data from a database and in that data it has variables in there, so when the data is outputted the variables should be replaced, but this is not happening.


$subid=$_COOKIE["lnm_lead_subid"];
$adid=$_GET["adid"];

$string = $pixelurl;
$string = addslashes($string); 
echo $string;

Output is below:

http://www.URL.com/tracking/RecordPixel.aspx?cmp=120&optional=$adid&optional2=$subid&optional3=

As you can see $adid and $subid are still in the output and have not been replaced. Any help would be great.

Thank you.

bump

We’ll need to see more of your code. Where do you set the value of $pixelurl?

Here you go :slight_smile:



$query2 = sprintf("SELECT Pixel FROM affpixels WHERE AffID ='%s' AND ProID ='%s'",
			quote_smart($affid),
			quote_smart($p));

mysql_query($query2) or dies(mysql_error()); 
$result2 = mysql_query($query2);
$pixelurl=$result2;

while($row = mysql_fetch_array($result2))
  {
  //echo $row['Pixel'];
  $pixelurl=$row['Pixel'];
  }


Any help would be great.

Thanks

You are not providing enough to be able to determine the problem.

Can you post the code that echoes/prints the URL:

http://www.URL.com/tracking/RecordPixel.aspx?cmp=120&optional=$adid&optional2=$subid&optional3=

I already have in the first post.

Thanks

Without having the entire script in front of me, my best guess is that you are pulling “http://www.URL.com/tracking/RecordPixel.aspx?cmp=120&optional=$adid&optional2=$subid&optional3=” straight from the database and expecting $adid and $subid to be substituted in to it automagically, but that is not happening.

Try doing this:

$subid=$_COOKIE["lnm_lead_subid"];
$adid=$_GET["adid"];

$string = $pixelurl;
$string = addslashes(str_replace(array('$subid', '$adid'), array($subid, $adid), $string));
echo $string;  

Yep that’s fixed the issue.

Thanks :slight_smile: