从多维输入形式将数据插入到mySQL表中 [英] Inserting data into mySQL table from mutlidimensional input form

查看:133
本文介绍了从多维输入形式将数据插入到mySQL表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道什么是从多维形式将数据插入数据库的最好方法。我的表单输入的名称如下:

I wonder what's the best way to insert data into a database from a multidimensional form. The name of my form inputs is something like below:

name="order[][quantity]"
name="order[][description]"
name="order[][article]"
name="order[][price]"
name="order[][tax]"
name="order[][discount]"

我的数据库?以下是我的表单图片:

How to insert this data into my database? Below is a image of my form:

正如你可以看到,用户可以添加许多部分,并且所有都由一个提交按钮处理。订单数是一个变量。

As you can see the user can add many sections and all are to be handled by one submit button. Number of orders is a variable.

如何解决此问题?

推荐答案

假设是..

<input type='text' name='quantity[]'>
<input type='text' name='description[]'>
<input type='text' name='article[]'>
<input type='text' name='price[]'>
<input type='text' name='tax[]'>
<input type='text' name='discount[]'>

Submit_Some_Page.php

<?
extract($_POST);

$TotalArticle=sizeof($article);

for($i=0;$i<$TotalArticle;$i++)
{
    $Article=$article[$i];
    $Quanity=$quantity[$i];
    $Price=$price[$i];
    $Tax=$tax[$i];
    $Discount=$discount[$i];
    $Description=$description[$i];

    <-- Now, Write Insert Query Here..
    $Query="INSERT INTO TableName SET Col1Name=$Article,Col2Name=$Quanity,Col3Name=$Price,Col4Name=$Tax,Col5Name=$Discount,Col6Name=$Description";
      ..... Write Mysql Query To Execute It
}
?>

这篇关于从多维输入形式将数据插入到mySQL表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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