0

i am getting a querystring parameter like companyname=Larson&tubro. Its a single string. But my script is just breaking it after '&'. What is the solution to take this as a single string in PHP. I tried like the below:

 <A onclick="window.open('comparitive_files/price_add.php?supplier_name= + urlencode({$supplier_name})&amp;tender_id={$tender_id}','mywindow','width=1200,height=800,scrollbars=yes,resizable=yes')" 
  href="#">
2
  • Please post the code you are using. It will make it easier to debug the issue. Commented Nov 2, 2015 at 12:28
  • 1
    You are trying to use php functions in javascript. Commented Nov 2, 2015 at 12:42

4 Answers 4

2

You are trying to use php functions outside of php. Try something like this.

echo '<A onclick="window.open(\'comparitive_files/price_add.php?supplier_name='.urlencode($supplier_name).'&tender_id='.$tender_id.',\'mywindow\',\'width=1200,height=800,scrollbars=yes,resizable=yes\')" href="#">';
Sign up to request clarification or add additional context in comments.

Comments

1

You can try urlencode

 urlencode($var);

Comments

0

Use urlencode for encoding

 urlencode($companyname);

and urldecode for decoding

 urldecode($companyname)

Comments

-1

& is used to seperate variables in a querystring. Instead use &amp;.

To prevent any other illegal characters from getting in your querystring, use urlencode()

5 Comments

This companyname that is 'Larson&tubro' is coming from mysql db and i dont have control over it.
You have control over when you put it in the url right? use something like 'companyname=' + urlencode(databaseoutput)
i try to give the said urlencode like this..<A onclick="window.open('comparitive_files/price_add.php?supplier_name= + urlencode({$supplier_name})&amp;tender_id={$tender_id}','mywindow','width=1200,height=800,scrollbars=yes,resizable=yes')" href="#">......But not working
The &amp; you use should be an & in this case, since tender_id is actually a separate variable. Do you have some bigger example? The line where you print this?
In your example you are trying to use urlencode outside of php. Try using this: <A onclick="window.open('comparitive_files/price_add.php?supplier_name=<?= urlencode($supplier_name) ?>&tender_id={$tender_id}','mywindow','width=1200,h‌​eight=800,scrollbars=yes,resizable=yes')" href="#">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.