Results 1 to 10 of 10

Thread: [RESOLVED] php mysql special characters

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    67

    Resolved [RESOLVED] php mysql special characters

    Hi everyone, let me start by explaining the problem which I am having. I have a simple php, mysql application that ads, edits and deletes records, however my problem arises when I redisplay some edited text in a way:

    Lets say I use € symbol in html it is € so in my form entry I would write "€ 50" and save it so when the web page is viewed it will show € 50, so when I try to edit the number ot lets say 30 back in may edit page it will say €50 and when I re-save it it stores back into the db this "€ 50", so I was wondering if that has to do with php mysql special characters and how do I bypass it, any help is appreciated.

    This is my code:

    PHP Code:
    <?php
      
    if ($nid>0) {
        
    $query=mysql_query("SELECT * FROM `nekretnine` WHERE `nid`='".$nid."' LIMIT 1");
        while (
    $fetch=mysql_fetch_assoc($query)) {
    <
    form action="edit.php?id=<?php echo $nid; ?>" method="post">
    print 
    '<textarea id="textarea" type="text" name = "description" />'.$fetch['description'].'';
    print 
    '    </textarea>';
    print 
    '<input type="submit" value="Dodaj">';
    print 
    "</form>";  
     }
      } else {
        print 
    '<tr><td colspan="4">Not Saved try again</td></tr>';
      }   
    ?>
    I've red somwhere that I should use "html_entities(mysql_real_escape_string($variable));" but I don't know how to insert it in my code.

    Thank you.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: php mysql special characters

    I think this is what you are looking for:
    Code:
    print '<textarea id="textarea" type="text" name = "description" />'.html_entities($fetch['description']).'';
    Not sure what the mysql_real_escape_string function is or does... but if it turns out you need it then it looks like this:

    Code:
    print '<textarea id="textarea" type="text" name = "description" />'.html_entities(mysql_real_escape_string($fetch['description'])).'';
    Hope that helps....

    -tg
    ps - this shouldn't be in the codebank, which is for sharing usefull stull... I'll let a mod know to move it.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    67

    Re: php mysql special characters

    Quote Originally Posted by techgnome View Post
    I think this is what you are looking for:
    Code:
    print '<textarea id="textarea" type="text" name = "description" />'.html_entities($fetch['description']).'';
    Not sure what the mysql_real_escape_string function is or does... but if it turns out you need it then it looks like this:

    Code:
    print '<textarea id="textarea" type="text" name = "description" />'.html_entities(mysql_real_escape_string($fetch['description'])).'';
    Hope that helps....

    -tg
    ps - this shouldn't be in the codebank, which is for sharing usefull stull... I'll let a mod know to move it.
    Thanks for answering so quickli but when I do what you have suggested I get this error:
    Code:
    Fatal error: Call to undefined function: html_entities() in
    Dou you know why?

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: php mysql special characters

    because it would seem that it's htmlentities(). ...

    http://us2.php.net/manual/en/function.htmlentities.php

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: php mysql special characters

    Thread moved from "CodeBank - PHP" forum to "PHP" forum

    (thanks for letting us know tg )

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    67

    Re: php mysql special characters

    Quote Originally Posted by techgnome View Post
    because it would seem that it's htmlentities(). ...

    http://us2.php.net/manual/en/function.htmlentities.php

    -tg
    I don't understand it, can you please explain.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: php mysql special characters

    You used html_entities, but the function is actually called htmlentities (no _ )

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    67

    Re: php mysql special characters

    Quote Originally Posted by si_the_geek View Post
    You used html_entities, but the function is actually called htmlentities (no _ )
    Thanks for that!

    One more thing If I have a form which I use to input this information and it goes something like this:

    Code:
    <form enctype="multipart/form-data" action="add.php" method="POST">
    <textarea style="width:250px;height:80px;overflow:auto;" type="text" name = "description" />
    </form>
    add.php
    PHP Code:
    //This gets all the other information from the form
    $description=$_POST['description'];
    //Writes the information to the database
    mysql_query("INSERT INTO `det` VALUES ('','$description')") ; 
    How would I incorporate htmlentities() in to the code so it would store all of the special characters, and also how would I incorporate nl2brnl() into this code as well. I really appreciate your help.

  9. #9
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: php mysql special characters

    PHP Code:
    $description mysql_real_escape_string(htmlentities(nl2brnl($_POST['description']))); 

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    67

    Re: php mysql special characters

    Excellent stuff guys thank you for your hard work and help.

Posting Permissions

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



Click Here to Expand Forum to Full Width