Here’s my data from firebug
action=saveOrder&name=Aprova%C3%A7%C3%A3o+dos
On the server side I am trying to save it to database, the name column has collation – utf8_general_ci
Here’s my php script
1.
$name= htmlentities(str_replace("+", " ", rawurldecode($_POST["name"])));
I also tried
2.
$name= html_entity_decode(str_replace("+", " ", rawurldecode($_POST["name"])));
If you see this link
http://writecodeonline.com/php/
The 2. piece work there, but when I save it in database it’s not saved properly
with the last code piece the value that gets saved is Aprovação dos and with case 1.
it saves this Aprovação dos
The value that should get saved in database is Aprovação dos
function saveorders()
{
var params={};
params.action='saveOrder';
params.name=$("#cliente_nome").val();
$.post('saveorders.php',params,function(data)
{
alert(data);
});
}
PHP Code
<?php
mb_internal_encoding("UTF-8");
include_once ("clase.php");// Database connection file
session_start();
$name=html_entity_decode(str_replace("+", " ", rawurldecode($_POST["name"])));
Policy::saveOrders($name);
?>
Any help appreciated
Here are the steps I took to resolve this
[This one I took from the above answers, I am not sure which one to keep and which one to remove, I kept both as it worked for me]
3.while sending data using jquery use escape, so this becomes
params.name=$("#cliente_nome").val();this
params.name=escape($("#cliente_nome").val());e.g
<?php mb_internal_encoding("UTF-8"); iconv_set_encoding("internal_encoding", "UTF-8"); include_once ("clase.php");// Database connection file session_start(); $name=str_replace("+", " ", rawurldecode($_POST["name"])); Policy::saveOrders($name); ?>