how do I escape quote a string inside of an escape-quoted string?

Posted on 2007-10-04
Last Modified: 2012-05-05
I'm writing a php webpage that builds a list of lunch orders for a student. these lunch orders are placed into a "shopping cart" until the order is submitted.

basically, to display the cart, the database is queried and the result is placed into an array called $line. if $line["Side1"] is not null, a table row is added to $cartHTML (a php string representing the html for the shopping cart). The contents of this table row can be described in pseudo-code as follows:

TD: link to delete the item that calls a js function
TD: description of the item
TD: item cost

here's a look at the php code that generates the table row. I took out some of the irrelevant code to make it easier to read:

if ($line["Side1"] != "") {       $cartHTML.=  "         <tr><td width=70%><a href=\"#\" class=\"trashcanLink\" onclick=\"deleteCheckoutItem('$studentid', '$menu', '`Side1ID`  =\'".$line["Side1ID"]."\' AND `ItemNo`=".$line["ItemNo"]."');\" ></a>".$line["Side1"] . "</td><td align=\"right\" valign=\"top\" width=30%>$".$line["Side1Amount"])."</td></tr>\n"; }

here is my problem:

I'm having trouble with my escaped quotes for the deleteCheckoutItem function. it is a js function. the 3 parameters are all strings so they need to be escaped. the 3rd parameter is a string that gets injected into an sql statement via AJAX, but the SQL string also has a string value that needs to be escaped inside the js parameter that is already escaped.

SIMPLY PUT: how do I escape quote a string inside of an escape-quoted string?

Question by:cnesb860
    LVL 142

    Accepted Solution

    you have to think like this:

    inside the quotes, you have to escape the quote plus it's escape character (\):

     " 'quote start  \\\'quoted string\\\'  quote end '  "
    LVL 1

    Author Closing Comment

    the final solution turned out to be pretty involved, but it essentially boiled down to your answer, angellll.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now