I'm having some issues with getting my array to work , I'm not sure how to structure my foreach loop correctly and also how to correctly add it to my query so it will insert .
This is my first attempt at arrays and even PHP , I need help understanding how to move forward with this and not be scared of arrays .The resuklt of this working correctly should take 6 text values and store them into the table in the DB . I think my main issues are with this line foreach($_POST['title'] as $idx => $title) to get things working but I may be wrong ..Thanks Again . I have looked at some of example but still cannot get my code to work or understand completely .
Thanks
HTML CODE
<form method="post" name="add_record" id="add_record" action="EnterNewAlbum.php">
<input type="text" name="title[]" value="title" size="32" required="required" />
<input type="text" name="artist[]" value="artist" size="32" required="required" />
<input type="text" name="country[]" value="country" size="32" required="required" />
<input type="text" name="company[]" value="company" size="32" required="required" />
<input type="text" name="price[]" value="200" size="32" required="required" />
<input type="text" name="year[]" value="100" size="32" required="required" />
<br /><br />
<input type="submit" action="EnterNewAlbum.php" name="add_record" id="add_record" value="Add" />
</form>
PHP CODE
<?php
if(isset($_POST['add_record'])) {
include 'dbconnection.php';
$con = mysqli_connect($dbsrvname, $dbusername, $dbpassword, $dbname);
echo "button press test";
foreach($_POST['title'] as $idx => $title) {
$add_entry = mysqli_query($con , "INSERT INTO albumsID (`title`,`artist`,`country`,`company`,`price`,`year`) VALUES ('".$title."', '" . $_POST['artist'][$idx] . "', '" . $_POST['country'][$idx] . "' , '" . $_POST['company'][$idx] . "' , '" . $_POST['price'][$idx] . "' , '" . $_POST['year'][$idx] . "' ");
}
}
?>