简体   繁体   English

如何使用textarea插入和显示从codeigniter到数据库的回车键或新行

[英]how to insert and display the enter key or new line from codeigniter to database using textarea

I'm using a textarea in my html and I also want to store my inputted word on my database by using codeigniter. 我在我的HTML中使用textarea,我也希望使用codeigniter将输入的单词存储在我的数据库中。 for example if i entered the word "Hello" and the next line is "World" 例如,如果我输入单词“Hello”,下一行是“World”

like 喜欢

Hello
World

view 视图

<textarea name=text></textarea>

and before passing it to the controller this is my javascript 在将它传递给控制器​​之前,这是我的javascript

function add_work_experience()
{
var P1 = document.getElementById('company');
var P2 = document.getElementById('job_title');
var P3 = document.getElementById('text');
var P4 = document.getElementById('date');
var P5 = document.getElementById('description');


if (P1.value != "" && P2.value != "" && P3.value != "" && P4.value != "" && P5.value != "")
{
    var data = P1.value + "|" + P2.value + "|" + P3.value
    P1.value = "";
    P2.value = "";
    P3.value = "";
    swoosh(data, path+'swoosh_employee/swoosh_work_experience', 'workexperiencedv');

}

controller,, let's say that the variable $P3 is the textarea 控制器,让我们说变量$ P3是textarea

parse_str($_SERVER['QUERY_STRING'],$_GET);
    $data = $_GET['h'];
    list($P1,$P2,$P3) = explode("|", $data);
    $this->emp->add_word($P1, $P2, $P3);

model 模型

public function add_word($text)
{
$data = array ('text' => $text);      

$this->db->insert('word', $data);
}

and by displaying it 并通过显示它

<?php echo nl2br($text);?>

but it is not working. 但它不起作用。 Is there something that i will do on my mysql server? 我会在我的mysql服务器上做些什么吗? or in my codeigniter? 还是在我的codeigniter? or in my php? 还是在我的PHP? help. 救命。 i dont know what to do. 我不知道该怎么办。

尝试使用nl2br将textarea中的新行转换为br标记:

$text = nl2br($this->input->post('text'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP和MYSQL插入具有textarea的数据库(将新行和新行插入数据库)? - PHP & MYSQL Insert into database with a textarea (new line & new line into database)? 将Enter作为新行从textarea标记转换为div标记 - Convert Enter as new line from textarea tag into div tag 如何在 codeigniter 中将新用户数据插入数据库 4 - How to insert new user data into database in codeigniter 4 Textarea:按Enter键创建新行 - Textarea: pressing enter creates new line 如何使用“|”字符将Textarea中的值插入数据库? - How To Insert Value From Textarea To Database With “|” Characters? 通过 php 从 textarea 字段的每一行插入数据库 - insert in database from each line of textarea field by php 如何从每行都是记录的文本区域一次将大量记录插入数据库? - How can I insert a lot of records into database all at once from a textarea where every line of it is a record? Laravel从textarea获取每一行并插入数据库中的新行 - Laravel get each of lines from textarea and insert into new row in database 如何在数据库中插入“ Enter” - How to insert “Enter” in database 如何使用bootstrep模态代码igniter显示数据库中的详细数据? - How to display the detailed data from the database using bootstrep modal codeigniter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM