0

I'm still learning php and I still haven't figured out when to use ' or ". I'm guessing thats the problem with this code. It redirects me to the right page but the $loc variable isn't carried over.

 <?php header("Location: roomdata.php?loc=$loc"); ?>

on the page that has the header() commaned I also have an include command...

<?php  include 'include/globalscripts.php';  ?>

and in the globalscripts.php is...

<?php if( isset($_GET['loc']))?>

<?php $loc = $_GET["loc"];?>
3
  • Add more info like what the $loc is and how you derive it, code looks fine, the problem could be in how you construct $loc Commented Nov 19, 2012 at 23:27
  • Read about strings so you will know the difference between single and double quotes. Likely that isn't your issue as that syntax is correct. Maybe $loc isn't in the scope where you run that code. Commented Nov 19, 2012 at 23:29
  • @techouse can you define a $_SESSION variable in a link? the reason I ask is because I need it to be defined by where the user clicks on an image map. EX: <area shape="rect" coords="502,583,536,651" alt="D06" href="roomdata.php?loc=D06" /> Commented Nov 19, 2012 at 23:38

3 Answers 3

1

I would personally use:

<?php
    header('Location: roomdata.php?loc='.$loc);
?>
Sign up to request clarification or add additional context in comments.

1 Comment

in this case you could use single quotes
1
<?php if( isset($_GET['loc']))?>

<?php $loc = $_GET["loc"];?>

TRY

<?php
    if( isset($_GET['loc'])){
        $loc = $_GET["loc"];
    }
?>

2 Comments

Yes, @LifeByte really needs to stop wrapping every line in <?php ?> tags. It is confusing, unnecessary, and will likely introduce extraneous whitespace into the output that will conflict with calls like header().
yes, and of course do make sure a GET var with the key loc is actually passed :)
0

Your code should work, are you sure $loc is defined at this point?

Regarding ' and ":

$value = "derp";
echo "the value is:\t$value";
//output: the value is:     derp

echo 'the value is:\t$value';
//output: the value is:\t$value

Comments

Your Answer

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