dwex Posted January 22, 2011 Share Posted January 22, 2011 I have six rows of text boxes for users to enter into. The fields are named like ROW1: invqty, invpart, invdesc, invlist, invprice, parttotal ROW2: invqty02, invpart02, invdesc02, invlist02, invprice02, parttotal02 ROW3: ... ROW4: ... How can I add these to variables so $invoiceqty = invqty, invqty2, invqty3, etc. $invoicepart = invpart, invpart02, invpart03, etc. and then loop through them, inserting all rows into a table until all data is INSERTED Link to comment https://forums.phpfreaks.com/topic/225275-foreach-insert-multiple-array/ Share on other sites More sharing options...
Pikachu2000 Posted January 22, 2011 Share Posted January 22, 2011 Hard to say without seeing the form, knowing the database structure, what values go where, etc. Link to comment https://forums.phpfreaks.com/topic/225275-foreach-insert-multiple-array/#findComment-1163404 Share on other sites More sharing options...
dwex Posted January 22, 2011 Author Share Posted January 22, 2011 don't really have the codes for these at the moment but a rough example would be like this.. I will like to send all 3 users into the database with their information using a foreach loop <form method="POST" action="input.php"> <!-- Person #1 --> <input type="text" name="username[]" /> <input type="text" name="phonenum[]" /> <!-- Person #2 --> <input type="text" name="username[]" /> <input type="text" name="phonenum[]" /> <!-- Person #3 --> <input type="text" name="username[]" /> <input type="text" name="phonenum[]" /> <input type="submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/225275-foreach-insert-multiple-array/#findComment-1163405 Share on other sites More sharing options...
dwex Posted January 22, 2011 Author Share Posted January 22, 2011 think I got it already , thanks for viewing. Link to comment https://forums.phpfreaks.com/topic/225275-foreach-insert-multiple-array/#findComment-1163409 Share on other sites More sharing options...
dwex Posted January 22, 2011 Author Share Posted January 22, 2011 Okay , I managed to bring in all informations into the database except the image? This is how my foreach loop looks like. foreach ($_POST['name'] as $row=>$name) { $item = $name; $type = $_POST['tabledrop'][$row]; $price = $_POST['price'][$row]; $des = $_POST['description'][$row]; $stk = $_POST['stock'][$row]; $file = $_POST['pbimage']['name'][$row]; $target_path = "C:/xampp/htdocs/paintball/itemimages/"; $target_path = $target_path . basename( $_FILES['pbimage[]']['name[]']); if(move_uploaded_file($_FILES['pbimage[]']['tmp_name[]'], $target_path)) { echo "The file ". basename( $_FILES['pbimage[]']['name[]']). " has been uploaded/"; } $query = "INSERT into $type SET {$type}_name = '$item' , {$type}_price = '$price' , {$type}_image = '$file', {$type}_description = '$des' , {$type}_stock = '$stk' , {$type}_time = NOW()" ; $result = mysqli_query($link, $query) or die(mysqli_error($link)); } Link to comment https://forums.phpfreaks.com/topic/225275-foreach-insert-multiple-array/#findComment-1163417 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.