将多个文本框条目添加到mysql数据库 [英] Adding multiple textbox entry to a mysql database

查看:72
本文介绍了将多个文本框条目添加到mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含5个文本框的表单,我想在数据库中添加这5个条目。我想使用文本框数组,这样我可以在保存到数据库时使用for-each。作为任何人,任何代码如何做到这一点,或可以指引我在正确的道路?

I have created a form, with 5 textbox fields and I want to add those five entries in the database. I want to use the textbox "array", that way I can use a for-each when saving to the database. As anyone, any code on how to do this or can direct me in the right path?

input type="text" value="whateva" name= ?php text[0] ?> 
input type="text" value="whateva" name= ?php text[1] ?> 
input type="text" value="whateva" name= ?php text[2] ?> 

if (isset($_POST['Submit']) {
  //add to db
  (for-each $text as $val) {
    //add to db
  }
}

这可能吗?

推荐答案

HTML

HTML

<input type="text" value="whateva" name="text[]" />
<input type="text" value="whateva" name="text[]" />
<input type="text" value="whateva" name="text[]" />



PHP

if (!empty($_POST['text'])) {
    foreach ($_POST['text'] AS $value) {
        // add to the database
        $sql = 'INSERT INTO tableName SET fieldName = "' . mysql_real_escape_string($value) . '"';
    }
}

这篇关于将多个文本框条目添加到mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆