Adding a variable, variable to a query string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tdock
Forum Newbie
Posts: 5
Joined: Mon Oct 23, 2006 7:48 am

Adding a variable, variable to a query string

Post by tdock »

I am trying to create a dynamic confirmation page that passes variables and then redirects to an outside site. I am attempting to pass variables in the query string of a <img src=”url.php”> tag to my conversion tracking page. Everything works except the variables don’t pass to my tracking page. I assume the variables have been defined correctly because I can echo them to the screen.

I can’t figure out why this doesn’t work.

Is there a better way?

I am new to php and any help would be greatly appreciated.

Code: Select all

<html>

<?php

$id = $_GET['id'];

$user = "myusername";

$pass = "mypassword";

$database = "mydatabase";

$con = @mysql_connect('localhost',$user,$pass)or die("Unable to connect to MySQL");

@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT * FROM exit_links WHERE id='$id'";

$result = mysql_query($query,$con) or die(mysql_error());

while($row = mysql_fetch_array($result))
  {
   $type = $row['type'];
   $value = $row['value'];
   $name = $row['name'];
   $description = $row['description'];
   $url = $row['url'];
  }
?>

<body>

<!--Start Conversion Tracking Code-->
<br>
<img src="http://mysite.com/tracking/a.php?type=<?php $type ?>&value=<?php $value ?>&id=<?php $id ?>=&name=<?php $name ?>&description=<?php $description ?>" width=1 height=1>
<br>
<!--End Conversion Tracking Code-->

<?php

echo "<h1>You Are Leaving mysite.com
     <br>
     One Moment Please...</h1>       
     <br>
     <h5>If the page dosen't open in 3 seconds <a href=".$url.">Click Here</a>        
     to open manually.</h5>";

echo "<meta http-equiv='Refresh' content='3; URL=".$url."'>";

?>

</body>

</html>
Last edited by tdock on Thu Oct 26, 2006 8:42 am, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

tdock wrote:Everything works except the variables don’t pass to my tracking page. I assume the variables have been defined correctly because I can echo them to the screen.
can easily be checked. Just open your browser's source view and see wether the parameters are there or not.
I bet they are not since there is no echo in
<?php $type ?>
and the other variables.
tdock
Forum Newbie
Posts: 5
Joined: Mon Oct 23, 2006 7:48 am

Post by tdock »

Ok, so I viewed the source and the variables are not in the string. How do I fix this?

If I drop this echo into the code I see the variables values.

Code: Select all

echo $id . " " . $type . " " . $value . " " . $name . " " . $description . " " . $url;
Why don’t the variables pass to the query string?
Last edited by tdock on Thu Oct 26, 2006 8:41 am, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

volka wrote:I bet they are not since there is no echo in
<?php $type ?>
and the other variables.
Easy to fix

Code: Select all

<?php echo $type; ?>
tdock
Forum Newbie
Posts: 5
Joined: Mon Oct 23, 2006 7:48 am

Post by tdock »

Thanks a lot!
Post Reply