0

I'm trying to use paypal ipn in order to insert things into a database when an order is complete.

I need to insert a sentence in a sql database, the sentence is: "This is my sentence à é è"

The "é" and the "è" characters works completely fine but for the "à", it is replaced in the dabatase by "?".

I have litteraly no idea why the "à" doesn't work, I guess it's a problem with charset.

Here is my code:

$config = parse_ini_file('config.ini'); 
$conn = mysqli_connect($config['server_name'], $config['mysql_username'], $config['mysql_password'], $config['db_name']) or die(mysqli_error($conn)); 

mysqli_set_charset($conn, "utf8");

$mysql_qry_insert =  "SET NAMES utf8 ";
$resultttt = mysqli_query($conn,$mysql_qry_insert) or die(mysqli_error($conn ));

mb_internal_encoding("UTF-8");

$sentence = $customIpnPaypalVar;
$mysql_qry_insert2 =  "insert into dbTest values ('".mysqli_real_escape_string($conn,$customIpnPaypalVar)."')";
$resultttt = mysqli_query($conn ,$mysql_qry_insert2) or die(mysqli_error($conn ));

And the database show me: "This is my sentence ? é è".

I also tried to replace the à with à but it didn't work.

Thank you.

Edit:

I think that my problem come from paypal when passing datas from my form to the IPN, any ideas of what is going on ?

Edit 2: The problem come from Paypal for sure, when I pass a custom variable in the custom field from paypal Form and retrieve it in the ipn in log it shows me good accent but when I insert the variable in the database the accent doesn't work, why is that ?

Melvin Auvray
  • 57
  • 1
  • 7

1 Answers1

0

The solution of my problem was using mysqli prepared statement, for some reason the specials characters worked with this method. Moreover it seems to be more secure.

Thank you Magnus Eriksson for helping me there.

Melvin Auvray
  • 57
  • 1
  • 7