Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Header (Location) Using Query String

php query string header location

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1 jasonalien

jasonalien

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 194 posts

Posted 05 February 2013 - 07:40 AM

Hi, I have  a variable $a

And I want my webpage go to mypage.php?question_id=$a

I am trying to do this using

 

 header('Location : mypage.php?question_id=$a');
 

it doesn't work. I also tried several other possibilities and couldn't find the solution. Can you help me solving this please?

Thanks.



#2 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts

Posted 05 February 2013 - 08:30 AM

In PHP, the single quote strings (delineated by the ' character, as in your example), are not parsed for variables. You must use a double quoted string (with " characters) in order to have PHP parse and replace variables.

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3 jasonalien

jasonalien

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 194 posts

Posted 07 February 2013 - 11:39 AM

That helped, thank you!



#4 freshfish70

freshfish70

    CC Lurker

  • New Member
  • Pip
  • 6 posts

Posted 22 February 2013 - 03:47 AM

Single quote vs duble quote:

$s = "dollars";
echo 'This costs a lot of $s.'; // This costs a lot of $s.
echo "This costs a lot of $s."; // This costs a lot of dollars.

 

As you can see the variable won't output with single quotes because as greg said, PHP does'nt parse variables with single quotes.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download