Polish characters on site

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

  1. reQuorter

    reQuorter New Member

    Aug 15, 2008
    Likes Received:
    Trophy Points:
    Hello everyone,

    I am starting with my PHP adventure with this tutorial:


    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:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Language" content="pl" />
    @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">
    <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" />
    <h2>All Quotes:</h2>
    $query="SELECT `quote`, `author` FROM `quotes`";
    $result=mysql_query($query) or die(mysql_error());
    while ($i < $num) {
    $quote = htmlentities(mysql_result($result,$i,"quote"));
    $author = htmlentities(mysql_result($result,$i,"author"));
    echo("<blockquote>" . $quote . " ~ <cite>" . $author . "</cite></blockquote>");

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