SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Content Management Problem

    When I retrieve info from my database into an html form for editing some of the fields are blank or incomplete. I think the trouble is with the content of the database field not the PHP script. It seems as though punctuation marks (quotes, for instance) contained in the mysql field in question, along with the text within them, will be omitted from my html form when I try to retrieve it.

    I've tried adding:
    $title = htmlspecialchars($title);

    for each of the variables in my PHP script and their corresponding mysql fields, but it caused all of the textarea boxes in my html field to be returned empty. I've also changed the mysql field type from MEDIUMTEXT to LONGTEXT and then BLOB, but this seems to have no effect.

    Any help is appreciated.

  2. #2
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried stripslashes() or addslashes()?

  3. #3
    SitePoint Wizard
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    2,617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Things like " / " and the quotation mark, are used in PHP. Therefore, they need to be "hidden" from PHP.

    You should try:
    PHP Code:
    $titleaddslashes($title); 
    And then when you are going to output the text using a variable, you should do:
    PHP Code:
    $title stripslashes($title); 
    I am not certain of this, but I think that should do the trick.

    Edit:



    Hmmz, judging from the reply of delemtri, it seems I am on the right track


  4. #4
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Amazingly fast replies, thanks to both. I'll try this later but gotta go for now.

  5. #5
    SitePoint Addict Chris Roane's Avatar
    Join Date
    Jul 1999
    Location
    Helena, MT
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, that will work.

    Just remember to addslashes before adding content to a database and then strip slashes when you are displaying or editing content from a databse. Make sure you don't run any extra addslashes functions, because you will get a lot of slashes added before any quotation marks.

  6. #6
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't seem to have the proper syntax for this fix. Here's what I tried last to insert into mysql:

    $sql = "UPDATE details SET " .
    "id='$id', " .
    "cdid='$id', " .
    "title= addslashes('$title'), " .
    "image='$image', " .
    "blurb=addslashes('$blurb'), " .
    "biopic='$biopic', " .
    "bio=addslashes('$bio')," .
    "pic='$pic', " .
    "reviews=addslashes('$reviews') " .
    "WHERE id=$id";

    This returns: Error updating CD details: You have an error in your SQL syntax near '('The Joker\'s Wilde'), image='C:\\Inetpub\\wwwroot\\PHP\\sites\\kyle\\images\' at line 1

    Am I doing something dumb?

  7. #7
    SitePoint Addict Chris Roane's Avatar
    Join Date
    Jul 1999
    Location
    Helena, MT
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    $title = addslashes($title);
    $blurb = addslashes($blurb);
    $bio = addslashes($bio);
    $reviews = addslashes($reviews);

    $sql = "UPDATE details SET " .
    "id='$id', " .
    "cdid='$id', " .
    "title= '$title', " .
    "image='$image', " .
    "blurb='$blurb', " .
    "biopic='$biopic', " .
    "bio='$bio'," .
    "pic='$pic', " .
    "reviews='$reviews' " .
    "WHERE id='$id'";

    That should work.

    You technically don't even need the " . in this situation. I am not sure if that depends on the version of PHP though. I don't think you would need to do that in this case for PHP3 and PHP4.

    Hope this helps.

  8. #8
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This has helped, thank you. I can see that the data inserted into mysql is now formatted with slashes, When I retieve it, however, it is truncated in unexpected ways or missing entirely even though I can verify that the data is present in the database using phpmyadmin. I'll have to investigate a bit more but any thoughts on this latter trouble would be appreciated too!
    Thanks Again.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •