tags:

views:

35

answers:

3

I'm trying to pass variables using "get" in php, but ran into a snag.

Here's my PHP file:

<?php
 include '../includes/header.php';
?>
 <div id="page">
  <div id="content">
   <h3><?php $_GET['head']; ?></h3>
   <div id="screenshots"> <img src="../images/sites/<?php $_GET['img1']; ?>" /> <img src="../images/sites/<?php $_GET['img2']; ?>" /> </div>
   <div id="description">
    <p><?php $_GET['p1']; ?></p>
    <p><?php $_GET['p2']; ?></p>
   </div>
  </div>
 </div>
 <?php
 include '../includes/footer.php';
?>

To test it out I made a simple request:

<a href="work/test.php?head=a&img1=b&img2=c&p1=d&p2=e"><img src="images/sites/thumbs/thumb.jpg"/></a>

It goes to the correct page but none of the variables are getting seen. Did I make a stupid mistake somewhere? Thanks!

+5  A: 

You need to echo them all, here is an example:

  <p><?php echo $_GET['p1']; ?></p>
  <p><?php echo $_GET['p2']; ?></p>
Sarfraz
oh ok thanks! I knew I forgot something
JPC
@JPC: You are welcome :)
Sarfraz
If php.ini is setup for it (I think short_tags?) You can `<?= $_GET['p1']; ?>` the `=` is interrupted as "echo" saving the 6 extra characters. But it's not usually recommended.
Marco Ceppi
why isn't it recommended
JPC
@JPC: See this: http://perishablepress.com/press/2009/01/12/php-short-open-tag/
Sarfraz
A: 

You're not echoing your variables <?php $_GET['img1']; ?> should be <?php echo $_GET['img1']; ?>

Mchl
A: 

Your variables aren't getting written, you need an echo statement.

Try something like this:

<p><?php echo $_GET['p1']; ?></p>
Jimmy