POST Variables contains "+"

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
leon_nerd
Forum Commoner
Posts: 25
Joined: Tue Aug 21, 2007 1:20 pm

POST Variables contains "+"

Post by leon_nerd »

Hi Guys,

I am making some AJAX calls and passing some POST variables. The POST parameters happen to contain "+" character. It is something like prod1=A4+&prod2=fullsize. When I try to read the $_POST[prod1] it returns "A4 ". There is no + sign and it replaced by a white space instead. Am I doing something wrong? How can I read POST variables that contains "+" character.

Thanks in advance.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: POST Variables contains "+"

Post by AbraCadaver »

urlencode()
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
leon_nerd
Forum Commoner
Posts: 25
Joined: Tue Aug 21, 2007 1:20 pm

Re: POST Variables contains "+"

Post by leon_nerd »

I am making an AJAX call. So, I am building up the string using the javascript "+" to concatenate various variables for POST. Then I am using
http_request.open('POST', url, true);
. So, how can I use the urlencode() here since I am creating the parameter string in javascript?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: POST Variables contains "+"

Post by AbraCadaver »

leon_nerd wrote:I am making an AJAX call. So, I am building up the string using the javascript "+" to concatenate various variables for POST. Then I am using
http_request.open('POST', url, true);
. So, how can I use the urlencode() here since I am creating the parameter string in javascript?
I think it's this in js:

Code: Select all

url = escape(url);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: POST Variables contains "+"

Post by AbraCadaver »

Actually, you may only want to escape() the actual values and not the full url.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
leon_nerd
Forum Commoner
Posts: 25
Joined: Tue Aug 21, 2007 1:20 pm

Re: POST Variables contains "+"

Post by leon_nerd »

Ahh...I got it working. So silly of me. Just a simple encodeURIComponent() did the trick. Thanks a lot guys for your inputs. I really appreciate your time :)
Post Reply