foochuck Posted July 2, 2008 Share Posted July 2, 2008 I would like to pass $var1 to $masterVar so that both variables are exact copies - however I want to do this though a URL...(using the get method)... $var1 = "My text goes here"; http://www.thewebsite.com?masterVar=var1 However when I "get" $masterVar it comes out reading a string "var1" - I want it to read "My text goes here" Please help! FOO Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/ Share on other sites More sharing options...
trq Posted July 2, 2008 Share Posted July 2, 2008 http://www.thewebsite.com?masterVar=$var1 Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580253 Share on other sites More sharing options...
foochuck Posted July 2, 2008 Author Share Posted July 2, 2008 $masterVar = $_GET["masterVar"]; or $masterVar = $_GET[masterVar]; http://www.thewebsite.com?masterVar=$var1 Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580255 Share on other sites More sharing options...
trq Posted July 2, 2008 Share Posted July 2, 2008 $masterVar = $_GET["masterVar"]; Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580257 Share on other sites More sharing options...
foochuck Posted July 2, 2008 Author Share Posted July 2, 2008 The output of $masterVar still reads $var1 instead of My text goes here $masterVar = $_GET["masterVar"]; Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580263 Share on other sites More sharing options...
kenrbnsn Posted July 2, 2008 Share Posted July 2, 2008 How do you create the link? Please show us your code. Ken Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580288 Share on other sites More sharing options...
foochuck Posted July 2, 2008 Author Share Posted July 2, 2008 Page 1: $var1 = "This is my text"; <a href="http://www.thewebsite.com/project.php?masterVar=$var1">Link</a> Project.php Page: $masterVar = $_GET["masterVar"]; echo "$masterVar"; // This reads $var1 Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580294 Share on other sites More sharing options...
craygo Posted July 2, 2008 Share Posted July 2, 2008 use this $var1 = "My text here"; $masterVar = $$_GET['masterVar']; echo $masterVar; And the url will be http://www.thewebsite.com?masterVar=var1 Ray Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580298 Share on other sites More sharing options...
.josh Posted July 2, 2008 Share Posted July 2, 2008 show your actual code (in code tags). It looks to me like you're using single quotes around it so it's interpreting $var1 literally. You need to either have it in double quotes or not in quotes at all: echo "http://www.thewebsite.com/project.php?masterVar=$var1"; // or echo "http://www.thewebsite.com/project.php?masterVar=" . $var1; Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580303 Share on other sites More sharing options...
kenrbnsn Posted July 2, 2008 Share Posted July 2, 2008 Are you echoing the link via PHP or is it hard coded HTML? Ken Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580359 Share on other sites More sharing options...
foochuck Posted July 2, 2008 Author Share Posted July 2, 2008 I am using double quotes and I am echoing the link via PHP. I tried craygo's solution but nothing even shows up when I echo the $masterVar with that option. Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580375 Share on other sites More sharing options...
foochuck Posted July 2, 2008 Author Share Posted July 2, 2008 I tried this suggestion but it didn't work. I didn't receive any errors - and with this method not even $var1 showed up. use this $var1 = "My text here"; $masterVar = $$_GET['masterVar']; echo $masterVar; And the url will be http://www.thewebsite.com?masterVar=var1 Ray Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580379 Share on other sites More sharing options...
.josh Posted July 2, 2008 Share Posted July 2, 2008 show your actual code from source and target scripts (use code tags) seriously I think we're making a way bigger issue out of this than it really is. I mean, the only way it would literally echo out "$var" instead of the value of $var is if you're a) trying to echo out the link (with the variable) in single quotes, or b) your link is just plain text outside of php tags (regular html). There's really no other reason, except for that your script isn't being parsed at all, which it obviously is, as something is being received and echoed out. Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580383 Share on other sites More sharing options...
foochuck Posted July 3, 2008 Author Share Posted July 3, 2008 Page 1: $var1 = "This is my text"; http://www.thewebsite.com/projects.php?masterVar=var1 Project.php Page: $masterVar = $_GET["masterVar"]; echo "$masterVar"; // This reads $var1 - I'd like it to read This is my text Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580587 Share on other sites More sharing options...
mmarif4u Posted July 3, 2008 Share Posted July 3, 2008 You use header for redirecting OR a click URL method to pass variable to next page. Show your complete code. Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580589 Share on other sites More sharing options...
foochuck Posted July 3, 2008 Author Share Posted July 3, 2008 I'm using a basic click URL method to pass the variable to the next page... <a href="http://www.thewebsite.com/projects.php?masterVar=var1">My Link</a> Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580591 Share on other sites More sharing options...
.josh Posted July 3, 2008 Share Posted July 3, 2008 Page 1: $var1 = "This is my text"; http://www.thewebsite.com/projects.php?masterVar=var1 Project.php Page: $masterVar = $_GET["masterVar"]; echo "$masterVar"; // This reads $var1 - I'd like it to read This is my text Okay man, I don't mean to sound rude, but you got to focus here.... You keep showing separate little chunks of code. That does nothing for us. You need to copy/paste your entire code. You said earlier you are echoing your link, with quotes, without quotes, etc.. but you just keep pasting a link out of context. Not counting security issues, this is what your code should look like, no more, no less: page1.php <?php $var1 = "This is my text"; echo "<a href = 'http://www.thewebsite.com/projects.php?masterVar=$var1'>my link</a>"; ?> projects.php <?php $masterVar = $_GET['masterVar']; echo $masterVar; // output: This is my text ?> Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580592 Share on other sites More sharing options...
mmarif4u Posted July 3, 2008 Share Posted July 3, 2008 Crayon Violent is right. Follow his code. Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580596 Share on other sites More sharing options...
foochuck Posted July 3, 2008 Author Share Posted July 3, 2008 Thanks for everyone's help with this topic. The problem was that I wasn't using the a tag / url in an echo function. FOO Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580823 Share on other sites More sharing options...
.josh Posted July 3, 2008 Share Posted July 3, 2008 umm...do you mean to say that you forgot the </a> ? There's no possible way that that would cause your variable to be passed literally. The only three ways it could be passed literally is a) you had single quotes around it b) it was not wrapped in <?php ... ?> tags as an echo. c) your server doesn't recognize and therefor isn't parsing it (which we ruled out) Those are the ONLY three ways. I'm just trying to make this very clear for you, because I don't want you walking away thinking that php code breaks like that when not closing an html tag. It could make what's echoed out look funny markup-wise, but it cannot in any way determine literal vs. figurative interpretation. Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580828 Share on other sites More sharing options...
foochuck Posted July 3, 2008 Author Share Posted July 3, 2008 Understood. Thanks Crayon. umm...do you mean to say that you forgot the </a> ? There's no possible way that that would cause your variable to be passed literally. The only three ways it could be passed literally is a) you had single quotes around it b) it was not wrapped in <?php ... ?> tags as an echo. c) your server doesn't recognize and therefor isn't parsing it (which we ruled out) Those are the ONLY three ways. I'm just trying to make this very clear for you, because I don't want you walking away thinking that php code breaks like that when not closing an html tag. It could make what's echoed out look funny markup-wise, but it cannot in any way determine literal vs. figurative interpretation. Quote Link to comment https://forums.phpfreaks.com/topic/112967-solved-url-get-pass-a-variable-name-to-another-variable-in-a-url/#findComment-580830 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.