Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Polish characters on site
Old 08-15-2008, 02:59 PM Polish characters on site
Junior Talker

Posts: 3
Name: reQuorter
Trades: 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);
?>
reQuorter is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-15-2008, 06:14 PM Re: Polish characters on site
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Have you set the language of the database correctly? In PHPMyAdmin change it to: utf8_unicode_ci
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 08-16-2008, 12:53 PM Re: Polish characters on site
klikers's Avatar
Junior Talker

Posts: 4
Name: Piotr
Location: Poland, Poznan
Trades: 0
You should set third argument (charset) in htmlentities function because it's using iso-8859-1 (default).
Read more: http://php.net/manual/function.htmlentities.php
klikers is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Polish characters on site
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11493 seconds with 12 queries