Click here to Skip to main content
15,891,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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


HTML
<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);
            }
        }
    }   
?>
Posted
Comments
AnvilRanger 26-Dec-15 9:58am    
Magic? There is nothing magic about PHP. It is just like every other language out there it will do exactly what you tell it to do. Now along with your code describe the error you are facing.
[no name] 26-Dec-15 10:23am    
a 5!

1 solution

you should specify how many produtc you want to store in that single row of a table first
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900