gple Posted October 8, 2007 Share Posted October 8, 2007 I have a link like this: $descr="I love New York"; a href=add_prod.php?descr=$descr; This only passes I and not the whole string of words. Quote Link to comment https://forums.phpfreaks.com/topic/72337-passing-variables/ Share on other sites More sharing options...
sKunKbad Posted October 8, 2007 Share Posted October 8, 2007 You need to URL encode the string. See urlencode() in the php manual. Quote Link to comment https://forums.phpfreaks.com/topic/72337-passing-variables/#findComment-364757 Share on other sites More sharing options...
mkosmosports Posted October 8, 2007 Share Posted October 8, 2007 You have to urlencode the $descr variable if you want to pass it into a URL, so: $descr=urlencode("I love New York"); echo('<a href=add_prod.php?descr=$descr'); Quote Link to comment https://forums.phpfreaks.com/topic/72337-passing-variables/#findComment-364758 Share on other sites More sharing options...
kenrbnsn Posted October 8, 2007 Share Posted October 8, 2007 You need to enclose the whole "href" in quotes: <?php $descr = "I love New York"; echo '<a href="add_prod.php?descr=' . $descr . '">Some text</a>'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/72337-passing-variables/#findComment-364759 Share on other sites More sharing options...
mkosmosports Posted October 8, 2007 Share Posted October 8, 2007 Hey kenrbnsn, I noticed you didnt put any brackets when echoing. ie: echo '<a href="add_prod.php?descr=' . $descr . '">Some text</a>'; vs. echo ('<a href="add_prod.php?descr=' . $descr . '">Some text</a>'); Is this preferred? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/72337-passing-variables/#findComment-364762 Share on other sites More sharing options...
trq Posted October 8, 2007 Share Posted October 8, 2007 The braces are unneeded because echo is a language construct, not a function. Quote Link to comment https://forums.phpfreaks.com/topic/72337-passing-variables/#findComment-364764 Share on other sites More sharing options...
mkosmosports Posted October 8, 2007 Share Posted October 8, 2007 Thanks thorpe. Another bad habit I somehow picked up and gotta get rid of. Quote Link to comment https://forums.phpfreaks.com/topic/72337-passing-variables/#findComment-364768 Share on other sites More sharing options...
gple Posted October 8, 2007 Author Share Posted October 8, 2007 I am passing this variable to a text box in the new page but between each word is "+". How do you get rid of that. Quote Link to comment https://forums.phpfreaks.com/topic/72337-passing-variables/#findComment-364775 Share on other sites More sharing options...
trq Posted October 8, 2007 Share Posted October 8, 2007 Funnilly enough, urldecode(). Quote Link to comment https://forums.phpfreaks.com/topic/72337-passing-variables/#findComment-364777 Share on other sites More sharing options...
gple Posted October 8, 2007 Author Share Posted October 8, 2007 Now it is only outputting the first set of characters before the "+" Quote Link to comment https://forums.phpfreaks.com/topic/72337-passing-variables/#findComment-364785 Share on other sites More sharing options...
kenrbnsn Posted October 8, 2007 Share Posted October 8, 2007 Please post the code snippet in question. Ken Quote Link to comment https://forums.phpfreaks.com/topic/72337-passing-variables/#findComment-364787 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.