Jump to content

[SOLVED] problem passing & to a DB


wmguk

Recommended Posts

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

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']);
?>

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?

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>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.