stripslashes problem (American Inch Marks = ")

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Terry

    #1

    stripslashes problem (American Inch Marks = ")


    I have a form that my wife uses to update her tennis racket website. I
    modified it to allow data entry, modify, and delete. If you enter an id
    number you get the matching record if there is one. The data from that
    record is now displayed in the form ready to change. The second submit
    of the same id updates the record.

    $description=$_ POST['description'];
    $grip=$_POST['grip']; // Sizes are in inches (")

    if ($id) {
    $query="SELECT * FROM `rackets` WHERE id=$id";
    // Standard stuff here

    if (($id)and($id== $oldid)) { //$oldid is a hidden input field
    $row[3]=$description;
    $row[4]=$grip;
    }

    <form>
    <textarea id=\"descriptio n\" name=\"descript ion\">$row[3]</textarea>
    <label>Grip Sizes </label><input type=\"text\" id=\"grip\"
    name=\"grip\" maxlength=\"60\ " size=\"60\" value=\"$row[4]\">
    [Submit]
    </form>

    $query="SELECT * FROM `rackets` WHERE 1 ORDER BY id DESC";
    echo "All Records in a table for review" // Displays properly

    $row[3] and [4] have escape characters \

    -------------------
    Added $row[3]=stripslashes($ description);
    $row[4]=stripslashes($ grip);

    $description will display whatever is entered ' and "
    $grip will truncate anything after the " when the record comes up for
    modification.

    The only difference I can see is one is a textarea, the other an input box.

    Any ideas welcomed (and thanks to anyone willing to wade through all
    this stuff).

    --
    TK
    Friendly and helpful customer support that goes above and beyond. We help you get the perfect domain name.

    Still Having a Ball










    ..

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
  • NC

    #2
    Re: stripslashes problem (American Inch Marks = &quot;)

    Terry wrote:[color=blue]
    >
    > <form>
    > <textarea id=\"descriptio n\" name=\"descript ion\">$row[3]</textarea>
    > <label>Grip Sizes </label><input type=\"text\" id=\"grip\"
    > name=\"grip\" maxlength=\"60\ " size=\"60\" value=\"$row[4]\">
    > [Submit]
    > </form>
    >
    > $description will display whatever is entered ' and "
    > $grip will truncate anything after the " when the record comes up for
    > modification.
    >
    > The only difference I can see is one is a textarea, the other an input box.[/color]

    Not only that; the "value" attribute in the "grip" input is enclosed in
    double quotes. So outputting a double quote inside the attribute
    closes the value. You need to replace double quotes with &quot; before
    outputting $row[4] (or simply run htmlspecialchar s() on it before
    outputting).

    Cheers,
    NC

    Comment

    • Andy Jeffries

      #3
      Re: stripslashes problem (American Inch Marks = &quot;)

      On Thu, 18 May 2006 10:20:17 -0500, Terry wrote:[color=blue]
      > <input type=\"text\" id=\"grip\"
      > name=\"grip\" maxlength=\"60\ " size=\"60\" value=\"$row[4]\">
      >
      > $description will display whatever is entered ' and " $grip will
      > truncate anything after the " when the record comes up for modification.[/color]

      The answer is simple, your content contains a " and the HTML attribute
      uses " to contain the value. So effectively you have this:

      value="12" racket"

      So the value trims after 12 and then has racket" after it.

      There are two ways round this:

      1) Hacky - use value='$row[4]' which will allow you to use " within the
      data

      2) Better - use htmlentities on the data before displaying it for editing
      using ENT_QUOTES to convert quotes to HTML entities. Browsers will
      display the proper character and allow editing as if it's a single
      character.

      Cheers,


      Andy


      --
      Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
      http://www.gphpedit.org | PHP editor for Gnome 2
      http://www.andyjeffries.co.uk | Personal site and photos

      Comment

      • Terry

        #4
        Re: stripslashes problem (American Inch Marks = &quot;)

        Andy Jeffries wrote:[color=blue]
        > On Thu, 18 May 2006 10:20:17 -0500, Terry wrote:
        >[color=green]
        >><input type=\"text\" id=\"grip\"
        >> name=\"grip\" maxlength=\"60\ " size=\"60\" value=\"$row[4]\">
        >>
        >>$descriptio n will display whatever is entered ' and " $grip will
        >>truncate anything after the " when the record comes up for modification.[/color]
        >
        >
        > The answer is simple, your content contains a " and the HTML attribute
        > uses " to contain the value. So effectively you have this:
        >
        > value="12" racket"
        >
        > So the value trims after 12 and then has racket" after it.
        >
        > There are two ways round this:
        >
        > 1) Hacky - use value='$row[4]' which will allow you to use " within the
        > data
        >
        > 2) Better - use htmlentities on the data before displaying it for editing
        > using ENT_QUOTES to convert quotes to HTML entities. Browsers will
        > display the proper character and allow editing as if it's a single
        > character.[/color]

        Thanks a Bunch. (NC too)

        Used 2) - not very strong at coding - but I am rather obsessive.

        --
        TK
        Friendly and helpful customer support that goes above and beyond. We help you get the perfect domain name.

        Still Having a Ball










        ..

        ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
        http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
        ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

        Comment

        • Mladen Gogala

          #5
          Re: stripslashes problem (American Inch Marks = &quot;)

          On Thu, 18 May 2006 10:20:17 -0500, Terry wrote:
          [color=blue]
          > Any ideas welcomed (and thanks to anyone willing to wade through all
          > this stuff).[/color]

          You have 2 choices:
          1) To use preg_replace instead of stripslashes
          2) In the affected fields replace " by the word "inch" and
          then do "stripslash es"

          --
          大红鹰娱乐平台采用顶级加密技术,确保用户数据与交易的安全无虞,让玩家能够放心畅玩。


          Comment

          Working...