PHP分割文本区域的内容并插入到mysql中
我需要知道如何使用 php 编码执行以下操作请
- 从文本区域中获取插入的文本,
- 分割每行的内容
- 将每一行作为具有自己的 id 编号的自己的行插入数据库中
有人可以告诉我如何执行此操作吗?
谢谢
编辑________
这是我到目前为止所尝试过的
$is_first = true;
foreach (explode('\n', $_POST['code']) as &$voucher) {
if ($is_first) $is_first = false; else $query .= ', ';
$query .= '(' . mysql_real_escape($voucher) . ')';
mysql_query('INSERT INTO back_codes (`code_id`, `code`) VALUES (NULL, "$voucher")');
}
I need to know how to do the following using php coding please
- take inserted text from a textarea
- split the content per line
- Insert each line into the database as its own row with own id number
Can anyone show me how to do this please?
thanks
EDIT________
THis is what I have tried so Far
$is_first = true;
foreach (explode('\n', $_POST['code']) as &$voucher) {
if ($is_first) $is_first = false; else $query .= ', ';
$query .= '(' . mysql_real_escape($voucher) . ')';
mysql_query('INSERT INTO back_codes (`code_id`, `code`) VALUES (NULL, "$voucher")');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它是通过 POST 请求发送的,则使用
$_POST['field_name']
引用它,如下所示:您可以使用
explode()
,就像这样:迭代
explode()
的结果,然后将行逐一插入数据库。Refer to it using
$_POST['field_name']
, if it has been sent with POST request, like that:You can split strings using
explode()
, like that:Iterate through result of
explode()
and then insert rows one-by-one to the database.我希望您通过提交 POST 表单数据从 textarea 发送数据。
假设您的文本区域如下所示:
那么在 PHP 中您可以使用以下代码:
I expect you sent data from textarea by submitting POST form data.
Let's say you textarea looks like this:
Then in PHP you can use following code: