wmguk Posted September 9, 2008 Share Posted September 9, 2008 Hey, I'm looking to pass & within some GET variables etc... the info is written and displayed in the database and on php pages fine, however when the variable is passed via a GET url it trips the page out... ie http://www.domain.co.uk/pop.php?coname=thisismycompany&iloveit.... I'm assuming it drops after & because & is a special code within the GET.... what can I do? Link to comment https://forums.phpfreaks.com/topic/123410-solved-problem-passing-amp-to-a-db/ Share on other sites More sharing options...
thebadbad Posted September 9, 2008 Share Posted September 9, 2008 From another topic: teamname.php?opponent=Texas A&M This will set $_GET['opponent'] to 'Texas A' and $_GET['M'] (to no value). Query string values can't contain literal ampersands, as that marks the next name=value pair. ... When creating/echoing the link, urlencode() the text you wanna pass through GET. Then urldecode() it again when displaying the text. <?php $text = 'thisismycompany&iloveit'; echo '<a href="http://www.domain.co.uk/pop.php?coname=', urlencode($text), '"></a>'; ?> In pop.php: <?php echo urldecode($_GET['coname']); ?> Link to comment https://forums.phpfreaks.com/topic/123410-solved-problem-passing-amp-to-a-db/#findComment-637390 Share on other sites More sharing options...
wmguk Posted September 9, 2008 Author Share Posted September 9, 2008 Hi, I've got this as the link: <? echo '<a href="pop.php?coname=', urlencode($coname), '" class="pageheader" onclick="window.open(', urlencode($coname), ','popup','width=500,height=215,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=300,top=300'); return false">Info</a>'; ?> and then this on the pop.php page <? $coname = urldecode($_GET['coname']) ; ?> but it still doesnt work? Any ideas? Link to comment https://forums.phpfreaks.com/topic/123410-solved-problem-passing-amp-to-a-db/#findComment-637592 Share on other sites More sharing options...
thebadbad Posted September 9, 2008 Share Posted September 9, 2008 You forgot to escape the single quotes in your javascript. And I also corrected the first parameter of the open() method to the URL, not just the coname: <?php echo '<a href="pop.php?coname=', urlencode($coname), '" class="pageheader" onclick="window.open(\'pop.php?coname=', urlencode($coname), '\',\'popup\',\'width=500,height=215,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=300,top=300\'); return false">Info</a>'; ?> Link to comment https://forums.phpfreaks.com/topic/123410-solved-problem-passing-amp-to-a-db/#findComment-637678 Share on other sites More sharing options...
wmguk Posted September 9, 2008 Author Share Posted September 9, 2008 Oh of course!! excellent thank you Link to comment https://forums.phpfreaks.com/topic/123410-solved-problem-passing-amp-to-a-db/#findComment-637690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.