Jump to content

Character encoding problem


T-Hawk

Recommended Posts

Hey all

I'm working on a site for my brothers friend and it has a commentary system.

The commentaries get added by calling a Javascript which updates the current page and then call a PHP script to store the comment in a mySQL database.

My problem is at if the user uses any kind of special chars like the danish chars: æ, ø and å then the PHP script will just die on them. It will store the message until the chars and then stop.

I've tried running an escape () in the javascript on the txt i'm sending, and i've tried using CONVERT ('string' USING utf8) in the SQL query.

The entire site is encoded in UTF-8, and so is the database but the user might type in ISO-8859-1 (?).

Somewhere else on the site i have a fileupload, here the page calls the upload script directly and it has no problems storing special chars in the database, so i'm thinking the problem might be a combination of the Javascript and PHP.

 

I'm hoping someone has an idea to what might be wrong.

 

The page can be seen on: http://t-hawk.com/david

User / pass: test / test

And yes the site is in danish, but the problem is in the section labelled: "Gæstebog", and if one clicks on one of the posts on the frontpage.

 

Thanks in advance

Link to comment
Share on other sites

I assume you do this:

 

<form action='<?php $_SERVER['PHP_SELF']; ?>' method='post'>
<input type='textarea' size='100' name='input' />
</form>

<?php

mysql_connect("localhost", "ken", "blah");
mysql_select_db("test");

$input = $_POST['input'];

$query = "INSERT INTO table (input) VALUES ('$input')";
mysql_query($query) or die(mysql_error());

?>

Link to comment
Share on other sites

As i said i use a Javascript to open a XMLRequest object and send the txt to a PHP script, that then does:

<?PHP
$query = "INSERT INTO `guestbook` (`name`, `mail`, `time`, `text`) VALUES (CONVERT ('"
.mysql_escape_string ($_REQUEST['name'])
."' USING utf8), CONVERT ('"
.mysql_escape_string ($_REQUEST['mail'])
."' USING utf8), '"
.$time
."', CONVERT ('"
.$_REQUEST['txt']
."' USING utf8));";
$query = mysql_query ($query);
dbErr ();
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.