Solved

unterminated string literal error

Posted on 2010-11-27
15
488 Views
Last Modified: 2012-05-10
hello

i am getting an error of unterminated string literal and cannot see where to correct it. it is not happening on all actions in the page just some, so i guess it is random. i have posted the code and would be grateful if someone could see the problem. thanks.
$action = str_replace("'", "\\'", "action.php?id=$id&slot=$slot&service=$service&company=$company&address=address&user=$custname&department=$department&activity=$activity&item=$item&filebox=$filebox&destroydate=$destroydate&date=$date&quantity=$quantity&type=$type&new=$new");

call in the page

<td valign=\"top\"><a href=\"#\" onClick=\"PopUp('" . $action . "','winAvail','status=no,scrollbars=no,resizable=yes,width=465,height=450');\">Action</a></td>

Open in new window

0
Comment
Question by:peter_coop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 3
15 Comments
 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 34221599
There must be a single quote (') in one of the values you use to build the $action.
It would be easy to check using the HTML that is generated.
0
 

Author Comment

by:peter_coop
ID: 34221625
hi
is this what you need? thanks
<td valign="top"><a href="#" onClick="PopUp('action.php?id=4731&slot=&service=Standard&company=FIDD&address=address&user=Some User&department=FIDD&activity=New Intake&item= 27469.4
&filebox=ABC 12040&destroydate=23/09/2016&date=2010-09-23 15:09:51&quantity=0&type=0&new=1','winAvail','status=no,scrollbars=no,resizable=yes,width=465,height=450');">Action</a></td>

Open in new window

0
 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 34221668
Yes, Is that line break before &filebox coming from the $item variable? that seems to be causing the problem.
Try removing the line break.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:peter_coop
ID: 34221744
there is no line break in original code. if you place this in notepad++ you will see it continuous code.

$action = str_replace("'", "\\'", "action.php?id=$id&slot=$slot&service=$service&company=$company&address=address&user=$custname&department=$department&activity=$activity&item=$item&filebox=$filebox&destroydate=$destroydate&date=$date&quantity=$quantity&type=$type&new=$new");


<td valign=\"top\"><a href=\"#\" onClick=\"PopUp('" . $action ."','winAvail','status=no,scrollbars=no,resizable=yes,width=465,height=450');\">Action</a></td>
0
 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 34221921
Sorry if I wasn't clear before. What I meant was not the code, but value that is in the variable $item

Because in the HTML code you posted, I got the same error when I use it in the same 2 line form as posted here. But when I remove the line break before the &filebox it worked.
<td valign="top"><a href="#" onClick="PopUp('action.php?id=4731&slot=&service=Standard&company=FIDD&address=address&user=Some User&department=FIDD&activity=New Intake&item= 27469.4&filebox=ABC 12040&destroydate=23/09/2016&date=2010-09-23 15:09:51&quantity=0&type=0&new=1','winAvail','status=no,scrollbars=no,resizable=yes,width=465,height=450');">Action</a></td>

Open in new window


Problem is in how the HTML is rendered in the client side (browser), not in the PHP code.
0
 

Author Comment

by:peter_coop
ID: 34221977
2 questions.

1) how do i correct code to make the code render correctly

2) this is not happening on every item. it seems random.

many thanks for your help.
0
 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 34222155
You can replace the line breaks from the $item before you use it in the code
$item=preg_replace("/[\r\n]/", "", $item);

Open in new window

0
 

Author Comment

by:peter_coop
ID: 34222185
thanks. but how do i incorporate that line into my code which posted earlier? thanks
0
 
LVL 18

Accepted Solution

by:
Sudaraka Wijesinghe earned 250 total points
ID: 34222218
You can add it just above the $action= line

$item=preg_replace("/[\r\n]/", "", $item);
$action = str_replace("'", "\\'", "action.php?id=$id&slot=$slot&service=$service&company=$company&address=address&user=$custname&department=$department&activity=$activity&item=$item&filebox=$filebox&destroydate=$destroydate&date=$date&quantity=$quantity&type=$type&new=$new");

call in the page

<td valign=\"top\"><a href=\"#\" onClick=\"PopUp('" . $action . "','winAvail','status=no,scrollbars=no,resizable=yes,width=465,height=450');\">Action</a></td>

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 34222234
Learn about this function.  You'll be glad you did!
http://us3.php.net/manual/en/function.urlencode.php
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 34222240
Also, it's very hard to catch errors in those long compound strings.  You might want to write your code like this, to make it easy to read and modify.

HTH, ~Ray
$action = "action.php"
. '?id='
. urlencode($id)
. '&slot='
. urlencode($slot)
. '&service='
. urlencode($service)
// etc...

Open in new window

0
 

Author Closing Comment

by:peter_coop
ID: 34222737
thank you for all your help. cheers
0
 

Author Comment

by:peter_coop
ID: 34222739
ray

thank you for your comments. unfortunately, i inherited this code but will bear in mind for future. thank you.
0
 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 34222845
Glad to help. Thanks for the points.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 34223199
@peter_coop:  

You accepted the wrong answer.  Please go back and read the man page for urlencode().  That is the correct way to get the strings encoded for HTTP transport.

"Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type."
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with mod_substitute 18 43
Survey branching tutorial 11 44
PHP Web Development 6 28
syntax error, unexpected '?' in phpunit 5 28
This article discusses four methods for overlaying images in a container on a web page
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question