Hello,
I am trying to create a little bit tricky part I thought I would be sucessfull but it didn't happend. Okay so I created a form having multiple field with the same name like users adds package details so it depends on him how much he would be able to or like to add by adding the add new field so the sissue is coming up the fiedls or not inserting in the database
pkginsert.php
<?php
require_once("connection.php");
echo $pkgname = $_POST["pkgname"];
echo $pkgprice = $_POST["pkgprice"];
echo $mnthprice = $_POST["mnthprice"];
if(isset($_POST["submit"])) {
echo $insert = mysqli_query($connection, "INSERT INTO packages (pkg_name, pkg_price, month_price) VALUES ('$pkname', '$pkgprice', '$mnthprice')");
$pkg_id = mysqli_insert_id($connection);
foreach($_POST["pkg_feature"] as $pkg_f) {
echo $data1 = mysqli_real_escape_string($connection, $pkg_f);
echo $insert1 = mysqli_query($connection, "INSERT INTO pkg_detail (pkg_feature, pkg_id) VALUES ('$data1', '$pkg_id')");
}
foreach($_POST["pkg_detail"] as $pkg_d) {
echo $data2 = mysqli_real_escape_string($connection, $pkg_d);
echo $insert2 = mysqli_query($connection, "INSERT INTO pkg_detail (pkg_detail, pkg_id) VALUES ('$data2', '$pkg_id')");
}
header("Location: packages.php?id=".$_SESSION['id']);
}
?>
newpkg.php
<form method="POST" action="includes/pkginsert.php">
<div class="form-group">
<label>Package Name</label>
<input class="form-control" name="pkgname">
</div>
<div class="form-group">
<label>Package Price</label>
<input class="form-control" name="pkgprice">
</div>
<div class="form-group">
<label>Monthly Price</label>
<input class="form-control" name="mnthprice">
</div>
<script type="text/javascript">
$(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append('<div class="form-group"><input type="text" name="pkg_feature[]" class="form-control alignleft" placeholder="Package Feature"/> <input type="text" name="pkg_detail[]" class="form-control alignleft" placeholder="Feature Detail" /><a href="#" class="remove_field"><i class="fa fa-times"></i></a><div class="clear"></div></div>'); //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
</script>
<div class="input_fields_wrap form-group">
<div class="form-group">
<button class="add_field_button btn btn-default">Add More Fields</button>
</div>
<div class="form-group">
<input type="text" name="pkg_feature[]" class="form-control alignleft" placeholder="Package Feature" />
<input type="text" name="pkg_detail[]" class="form-control alignleft" placeholder="Feature Detail" />
<div class="clear"></div>
</div>
</div>
<div class="form-group">
<input type="submit" class="btn btn-default" value="Submit Button" />
<input type="Reset" class="btn btn-default" value="Reset Value" />
</div>
</form>
so please let me know if anyone can help me out