I have 3 PHP files, in select.php file you have to select the number of forms that you want.. the form contain 3 input fields. as below:
<form method="post" action="index.php" >
Continue insertion with <select name="counters" id="insert_rows">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="3">3</option>
</select>
rows
<input type="submit" value="Go" />
</form>
After selecting the number of insertions, it will pass the number to index.php which is contain:
<?php
echo "<form method = 'POST' action = 'process.php'>";
for($counter = 0; $counter < $_POST['counters']; $counter++)
{
echo "Service Name: <input type = 'text' name = 'name[]' class = 'class_name'/><br/>";
echo "Service Version : <input type = 'text' name = 'version[]' class = 'class_name'/><br/>";
echo "Service type : <input type = 'text' name = 'type[]' class = 'class_name'/><br/>";
}
echo "<input type = 'submit' value = 'SEND'/>";
echo "</form>";
?>
the third file process.php contain
<?php
$name = array();
$version = array();
$type= array();
$name = $_POST['name'];
$version = $_POST['version'];
$type= $_POST['type'];
for($counter = 0; $counter < sizeof($name); $counter++)
{
echo "service_name #".($counter + 1).": ".$name[$counter]."<br />";
echo "service_version #".($counter + 1).": ".$version[$counter]."<br />";
echo "service_type #".($counter + 1).": ".$type[$counter]."<br />";
}
?>
and after i pass the value to it, it shows the data correctly as below
service_name #1: noway service_version #1: v1 service_type #1: Private service_name #2: bandar service_version #2: v2 service_type #2: Public
so my question is : how to create a function in 'process.php' file to insert all these values into the database.
I created a table called 'services' contain these columns "name,version,type"
I will be waiting for your support. thank you
var_dump($_POST)will tell you what you're getting in PHP. From there it's straight forward: grab some values, stuff them into the db. repeat until done.forloop that you use to build your form ->for($counter = 0; $counter < $_POST['name']; $counter++). For each form input, use the$counter->$_POST['name'][$counter],$_POST['version'][$counter],$_POST['type'][$counter]INSERTquery. 2.) Learn how to use mysqli or PDO. 3.) Learn how to handle form submissions in PHP. 4.) IF AND ONLY IF you are getting errors or are stuck on a specific problem, ask here. No one here is going to teach you how to do all of that.