views:

74

answers:

1

I'm having a heck of a time getting ♥ type characters into my database using php.

I've got UTF-8 setting on the page

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

and

<?php
$line = $_REQUEST['line'];
$line = stripslashes($line);
$line = htmlspecialchars($line);
$line = trim($line);
$line = mysql_real_escape_string($line);
mysql_query("SET CHARACTER SET utf8");

$sql = "INSERT INTO posts (txt) values ('$line')";
mysql_query($sql, $cn);

?>

the result of the insert is a ? character

i'm sure there are people who've done this, but I'm really having trouble getting it right.

edit:

the MySQL table's collation and field's encoding is also set to utf8_unicode_ci

+2  A: 

I believe you have to do: SET NAMES utf8 as your first query.

meder
ahhhhhh.... thank you so so so so much.this has been killing me for hours :D
Alex C
hmm it shouldn't be a reason. SET CHARACTER SET do the same as SET NAMES. And it's still before query execution. @Alex does it really slove your problem?
Col. Shrapnel
yeah it sure did! (i'd have voted for the green checkmark sooner but stack has a delay on accepting answers :)Maybe it's something to do with the version / settings / etc... on the server.
Alex C