SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    strange character

    I am using php and MySQL to build a database website, and encounter some data problem as some special charaters appearing as other strange character. For example, when the string "Podcast Advertising..." was entered in a form and stored into the MqSQL database, it is retrieved by the "select......." statement and displayed as "Podcast Advertising匶", ie, "..." appeared to be"匶". How can I solve this problem?

    The code of entering the entry is as:

    PHP Code:
    <form action=<?php echo $_SERVER['PHP_SELF']; ?> method='post'> 
    <label>Blog entry title:<br /> 
    <textarea name="title" rows="1" cols="100"> 
    </textarea></label><br /> 

    <input type='submit' value='SUBMIT' > 
    <input type='reset' name='RESET' value='RESET'> 
    </form> 

    <?php 
    if (isset($_POST['title'])) { 
    $title = ($_POST['title']); 
    $sql "INSERT INTO blog_entry SET 
    title='
    $title' "

    ?>

    the code of displaying the data is:

    PHP Code:
    $selectQuery3 "select distinct title from blog_entry where id = $docID "
    $result3 mysql_query($selectQuery3) or die("Unable to select documents"); 
    $displayTile mysql_fetch_array($result3); 
    $displayTile $displayTile[title]; 
    echo 
    "<td><a href = 'display_content.php?id=$docID'>$displayTile</a></td>"

  2. #2
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the data type on the columun title? Also what collation?

    And replace the following php code with the php code you have on your insert page
    PHP Code:
    <?php 
    if (isset($_POST['title'])) { 
    $title = ($_POST['title']); 
    $sql "INSERT INTO blog_entry SET 
    title='
    $title' "
    echo 
    $title;

    ?>

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, cmuench, the data type on the columun title is TEXT, and it is not a primary key, Null set to "yes", default is "NULL".

    Also, what is the purpose of adding "echo $title; " ?

    Thank you very much.

  4. #4
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to see whether the data gets screwed up server side or client side. What did it spit out?

  5. #5
    Non-Member melancholic's Avatar
    Join Date
    Nov 2004
    Location
    Australia
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It could be a charset issue

    Try changing the charset in a meta tag set content = iso-8859-1

    HTML Code:
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-8859-1">
    For your reference, here is a charset table:
    http://msdn.microsoft.com/workshop/a...s/charset4.asp


    Regards,

  6. #6
    Non-Member melancholic's Avatar
    Join Date
    Nov 2004
    Location
    Australia
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alternatively, the han character (匶) could be because your table is set to chinese collation. If this is so, change it back to utf-8 general that should fix it...

    these are just shots in the dark btw.

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The charset in a meta tag was set to content = iso-8859-1 already. But thanks to melancholic anyway. And how to change chinese collation to utf-8 general?
    (Sorry I am just a beginner )

  8. #8
    Non-Member melancholic's Avatar
    Join Date
    Nov 2004
    Location
    Australia
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm can't say that I've had any experience with issues like this myself, so I'm really just taking guesses

    Do you have phpmyadmin or anything that can view your database schema?
    Last edited by melancholic; Jul 17, 2006 at 08:23. Reason: damn it's late... replaced "mysql" with "phpmyadmin"

  9. #9
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, melancholic, I have phpMyAdmin installed. So how to view/edit the database schema?

    Thank you very much!

  10. #10
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just navigate to your database (dropdown to the left within phpMyAdmin). You'll see a list of tables belonging to that db along with collation info. It should say something like "latin1_swedish_ci". To change any table's collation, click on the table name and then on the "Operations" link (top right) where you'll see a dropdown with all charsets.

  11. #11
    Non-Member melancholic's Avatar
    Join Date
    Nov 2004
    Location
    Australia
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yah do what mudshark said.

    But in hindsight, I don't know exactly why it's doing that. I did some experiments today and I could not reproduce what's happening with your site.

    What I was thinking is that maybe and that's a big maybe at that.

    You said that you were using a form to enter data... are you using some sort of WYSIWYG editor or anything like that?

    When you view the data inside phpMyAdmin, does it look like the han character?

  12. #12
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know it, unfortunately, but try adding a charset/doctype to the form itself?

    I'm not 100% sure what I'm trying to say, if i saw it I'd know, but it's like

    <form multipart/data>? Or something...again a shot

    i'm sure some one here knows the correct term for what I'm on about

  13. #13
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ^^^ I think you're confusing this with what you need to do for uploading files using a form.
    Ian Anderson
    www.siteguru.co.uk

  14. #14
    Non-Member melancholic's Avatar
    Join Date
    Nov 2004
    Location
    Australia
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yah, I don't think it would be an enctype issue (although I've seen stranger things)

    I was asking about WYSIWYG's as some are a little buggy and mutate the content to something else in an attempt to do something clever.

    regards,


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
  •