1

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!

3 Answers 3

6

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

  <p><?php echo $_GET['p1']; ?></p>
  <p><?php echo $_GET['p2']; ?></p>
Sign up to request clarification or add additional context in comments.

1 Comment

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.
0

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

Comments

0

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

Try something like this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.