469,603 Members | 2,355 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,603 developers. It's quick & easy.

character encoding problem - (pound) sign

ben
Hi all,

I have a simple PHP page that takes values from a form and puts them in a
database (MySQL).

The code is in a file test.php, which I have typed in at the bottom of
this post (please excuse any typos). This page is not a production page -
I created it just to try and solve the sign problem I am having.

When I put the pound sign () into the input box and submit the form,
what gets inserted into mysql is an A with a ^ on top, followed by the
pound sign. I notice that the request URI shows the sign as %C2%A3. If
I run the query manually in php (i.e. mysql_query("INSERT INTO test
VALUES('')") ) then it is fine. (The problem occurs with both GET and
POST)

I have read up a bit about it and I believe that the problem is that one
part of the system uses UTF-8 while the other part uses ISO-8859-1. The
database is ISO-8859-1 (latin1).

Using phpmyadmin, I can put a sign into the database with no problem,
so I know that there must be a solution to this issue within PHP, but I
have no idea what it is!!!!

Any clues appreciated :)

Cheers,

Ben

--

test.php:

<?php
mysql_connect('localhost', 'root', '');
mysql_select_db("test");
mysql_query("INSERT INTO test VALUES('".$_REQUEST['testpound']."')");
?>
<HTML>
<BODY>
<form action="test.php">
<input name="testpound">
<input type="submit">
</form>
</body>
</html>
Oct 27 '05 #1
4 16528
The problem is indeed a character set one.

* Firstly, you need to have a HEAD element in your HTML. HEAD and
TITLE are not optional. This isn't really part of the problem though.

* Secondly, you should put the following in your HEAD:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"
/>
This will tell user agents what charset the page is being presented in,
rather than them having to guess. In the majority of cases this will
also govern which character set the form submission takes place in.
It's always a good idea to specify your charset in the page.

Oct 31 '05 #2
On 31 Oct 2005 08:57:21 -0800, "Ciaran" <ci***********@gmail.com> wrote:
* Secondly, you should put the following in your HEAD:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"
/>
This will tell user agents what charset the page is being presented in,
rather than them having to guess. In the majority of cases this will
also govern which character set the form submission takes place in.
It's always a good idea to specify your charset in the page.


It is a far better idea to send a true Content-type header, using header().
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Oct 31 '05 #3
ben
> It is a far better idea to send a true Content-type header, using
header().


That did it!

Cheers,

Ben
Nov 1 '05 #4
That's a very good point, I got into the habit of using META tags
because I used to just have shared, HTML-only hosting.

I guess there's no harm in doing both.

Nov 1 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Simon Harris | last post: by
9 posts views Thread by Joe Blow | last post: by
7 posts views Thread by Jim Lawton | last post: by
2 posts views Thread by Jim Lawton | last post: by
4 posts views Thread by monomaniac21 | last post: by
5 posts views Thread by Timothy Madden | last post: by
2 posts views Thread by withers | last post: by
2 posts views Thread by David Gillen | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.