Polish characters on site

Discussion in 'PHP' started by reQuorter, Aug 15, 2008.

  1. reQuorter

    reQuorter New Member

    Joined:
    Aug 15, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello everyone,

    I am starting with my PHP adventure with this tutorial:

    http://www.phazm.com/notes/easy-as-pie/eas...with-databases/

    Everything works fine, but when I add to database string with Polish characters (like ą, ż, ź, ć, ę, ł), I don't see them on site, instead of them I see strange characters.

    When I add to database through phpMyAdmin with Polish characters (like ą, ż, ź, ć, ę, ł) I see those characters in my table/rows correct (through phpMyAdmin).

    But when I'm displaying data on my site I again see those strange characters instead of Polish ones.

    MySQL Collation is utf8_bin (I also tired utf8_unicode_ci without success).

    I use this code:

    Code:
    <html>
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Language" content="pl" />
    
    </head>
    <body>
    
    <?php
    $user="username";
    $password="password";
    $database="database";
    $connection=mysql_connect('localhost',$user,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    
    if ($_REQUEST['quote'] != "") {
    	if($_REQUEST['author'] != "") {
    		$author = $_REQUEST['author'];
    	} else {
    		$author = "Anonymous";
    	}
    	$quote = $_REQUEST['quote'];
    	
    	$query="INSERT INTO `quotes` (`quote`,`author`) values ('" . mysql_real_escape_string($quote) . "','" . mysql_real_escape_string($author) . "')";
    	
    	$result=mysql_query($query) or die(mysql_error());
    	echo("inserted quote: " . htmlentities($quote) . " by " . htmlentities($author) . " into database");
    }  else {
    	echo("<p>Please enter a quote and author</p>");
    }
    ?>
    <form action="" method="post">
    <fieldset>
    <legend>Add a Quote</legend>
    <label for="quote">Quote:</label>
    <input type="text" name="quote" id="quote" maxlength="255" />
    <label for="author">Author:</label>
    <input type="text" name="author" id="author" maxlength="40" />
    <input type="submit" value="Add Quote" />
    </fieldset>
    </form>
    
    <h2>All Quotes:</h2>
    <?php
    
    $query="SELECT `quote`, `author` FROM `quotes`";
    $result=mysql_query($query) or die(mysql_error());
    $num=mysql_numrows($result);
    $i=0;
    while ($i < $num) {
    $quote = htmlentities(mysql_result($result,$i,"quote"));
    $author = htmlentities(mysql_result($result,$i,"author"));
    echo("<blockquote>" . $quote . " ~ <cite>" . $author . "</cite></blockquote>");
    $i++;
    }
    mysql_close($connection);
    ?>
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice