如何使用php的强大功能和魔力将更多产品的一个名称输入或插入数据库? [英] How to input or insert one name with more products into the database using the power and magic of php?

查看:53
本文介绍了如何使用php的强大功能和魔力将更多产品的一个名称输入或插入数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am trying to input one name with more products. the scenario here is when I input the Name:_______________ Product:______________ Product:_______________. It will the be inserted into the database and it will display like this:

Johnny | Iphone 
Johnny | Windows Phone







<table>
    <tr>
        <td>Name</td>
        <td><input type="text" name="name_txt[]" /></td>
    </tr>

    <tr>
        <td>Product</td>
        <td><input type="text" name="product_name_txt[]" /></td>
    </tr>

    <tr>
        <td>Product</td>
        <td><input type="text" name="product_name_txt[]" /></td>
    </tr>

    <tr>
        <td> </td>
        <td><input type="submit" name="submit" value="add" />
        <input type="reset" name="submit" value="clear" /></td>
    </tr>
</table>







<?php   

if(isset($_POST['submit']))
    {      
        include 'db.php';

        foreach($_POST['product_name_txt'] as $row => $value){

                    $name=$_POST['name_txt'][$row];
                    $product=$_POST['product_name_txt'][$row];

            $sql = "INSERT INTO request(p_name, product_name)
                    VALUES ('$name','$product')";

            if (mysqli_query($conn, $sql)) {
                    echo "New record created successfully";
            } else {
                echo "Error: " . $sql . "<br>" . mysqli_error($conn);
            }
        }
    }   
?>

推荐答案

_POST ['提交')))
{
包括'db.php';

foreach(
_POST['submit'])) { include 'db.php'; foreach(


_POST ['product_name_txt'] as
_POST['product_name_txt'] as


row =>
row =>


这篇关于如何使用php的强大功能和魔力将更多产品的一个名称输入或插入数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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