3
I own a textarea
in my code, where the user will insert access vouchers separated by ENTER.
My PHP code treats the typed values as follows:
$voucher = explode("\n",$voucher);
foreach ($voucher as &$varray)
{
$gravar = mysqli_query("INSERT INTO `vouchers` (voucher, tempo) VALUES ('$varray','$tempoBD')");
}
Where: $voucher
is the value of the textarea received via $_POST
and $tempoBD
is the value that the user select converted in format 00:00:00
.
The problem is: The voucher field is saving the value of the line + line break (\n
)!
What correction to my code need to be done to remove the line break in the voucher field for each record entered in the table?
Thank you!
Yeah, his answer is even better. Put he needs to pick up the spaces, got!
– Lucas de Carvalho
I must be doing something wrong. You are saving in the bank as {Trim( + line value + )}. I will try to correct the syntax here
– Jhonatan Junio
Dude, the syntax I solved. The problem is you kept saving it with a line break in the bank! If I give the UPDATE vouchers SET voucher = TRIM(REPLACE(REPLACE(voucher, CHAR(13),'), CHAR(10),')) command in the bank, it changes the records. Can you help me?
– Jhonatan Junio
@Jhonatanjunio are you sure it’s line breaking? the
trim()
should solve. It is not a<BR>
?– rray
@Lucascarvalho crase goes in table names, views, identifier fields in general is the escape character. Simple quotes only goes in values.
– rray
I did not know that, I never actually used. Thanks rray
– Lucas de Carvalho
I do, @rray .. It’s just that I didn’t talk, I’m taking the values of a textarea and breaking ENTER with n. In the bank is coming the value of the field+a line break. In Heidisql it even says "Line break Mac OS detected"
– Jhonatan Junio