Jump to content

[SOLVED] Name with Apostrophe in Query String


kjharve

Recommended Posts

Hi all.

 

The site I am working uses query strings in some of the admin functions. A list of users is displayed and the functions you can perform on their accounts are written as hyperlinks. I've already got one user registered "O'Neill" and although my queries work ok, the admin functions won't.

 

Here's the code:

 

echo "<a href='admin.php?changeuser=$changeuser&criteria=admin'>Change</a>";

 

The URL that is output is as follows:

 

admin.php?changeuser=o

 

I really want the URL to be:

 

admin.php?changeuser=o'neill&criteria=admin

 

Using addslashes simply adds a \ on the end of the URL.

 

Can anyone help me with this?

 

Thanks.

 

Kev

You should use urlencode when setting your url, eg

 

$changeuser = urlencode($changeuser);
echo "<a href='admin.php?changeuser=$changeuser&criteria=admin'>Change</a>";

 

Now when you use $_GET['changeuser'] use urldecode, eg

 

$changeuser = urldecode($_GET['changeuser']);

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.