-3

the problem:

I have 2 textareas, first one I use to send text to database (mysql) and the second is used to show the text retrieved. However, the line breaks from the first one aren't being applied to the second.

example:

hello
world

will appear like this:

hello world

when I checked the data I'm sending in the $_POST, I found that line break are being translated to this ' '

Array ( [memo_1] => fff ggg bbb )

and url encoded is like this:

memo_1: eee%E3%80%80ddd

other data removed from the array for the sake of brevity.

what I tried:

I tried to use nl2br, but since there are no \n in this text it doesnt work. I tried to use str_replace to change these characters to \n but also didn't work.

I'm not sure why are these weird characters are showing since I have the encoding set to UTF-8 and I'm sorry if this is not an encoding related problem.

update:

PHP: 5.6.38

mysql: 5.7.24 and the table collation is 'utf8_general_ci'

the project works inside a vagrant box: centos 6

saving:

include('./common/env.php');
include('./login_manager.php');

$virgin             = $_POST['virgin'];
$memo_1             = $_POST['memo_1'];
$memo_2             = $_POST['memo_2'];
$call_counterpart       = $_POST['call_counterpart'];
$call_status            = $_POST['call_status'];
$recall_time_temp       = $_POST['recall_time'];

$sql = "UPDATE call_history SET ";
$sql .= "memo_1 = '$memo_1', ";
$sql .= "memo_2 = '$memo_2', ";
$sql .= "call_status    = '$call_status', ";
$sql .= "call_counterpart   = '$call_counterpart', ";
if ($recall_time != "") {
    $sql .= "recall_time    = '$recall_time', ";
    $sql .= "recall_flag        = '1', ";
}
$sql .= "active_flag    = '1' ";
$sql .= "WHERE id = '$history_id' ";
}
mysql_query($sql);`

retrieving:

$sql = "SELECT c.*, s.name staff_name ";
$sql        .= "FROM call_history c ";
$sql        .= "LEFT JOIN staff s ON c.staff_id = s.id ";
$sql        .= "WHERE 1 ";
$sql        .= "AND c.active_flag = 1 ";
$sql        .= "ORDER BY c.id DESC ";
$rs         = mysql_query($sql);
Rev
  • 11
  • 4
  • That's appears to be a encoding problem. Check encoding of the page and the received value – Sakura Kinomoto Dec 08 '18 at 04:19
  • I checked the encoding of the value I'm sending and the page, both are UTF-8 – Rev Dec 08 '18 at 04:30
  • We need to see *how* you're saving and outputting this, and which OS you're running this off of. @Rev – Funk Forty Niner Dec 08 '18 at 04:41
  • Plus, about the encoding issue. There stands to be a reason or reasons why those characters are showing as that. There are too many reasons actually, this including the collation, which format the files were saved as, or the connection parameters. If you want more help, you can `@Funk` me here if you want my or someone else's direct attention, otherwise we won't know who you're talking to. – Funk Forty Niner Dec 08 '18 at 04:50
  • @FunkFortyNiner I updated the question with few things which I hope they are useful – Rev Dec 08 '18 at 05:06
  • 1
    Please, check this question https://stackoverflow.com/questions/279170/utf-8-all-the-way-through?rq=1 and verify you have utf-8 on all. Add on the question relevant information about encoding and checks. – Sakura Kinomoto Dec 08 '18 at 11:33

1 Answers1

0

It appears that the fault was not in the encoding after all. there was some lines of code written by another developer in the company that were interfering with the data being sent to the server that I had to fix in order to send valid data.

ps: I'm still new in the company hence not getting why the data being modified and thinking it was an encoding issue.

Rev
  • 11
  • 4