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); } } } ?>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)