0

I'm new to PHP coding so I have two questions to ask in the case that...

What if I want to get more input field by clicking the "+" button like the picture below

enter image description here

After click "+" button it will provide the input box like the picture below

enter image description here

So... first question, how can I do like this?

And second question, after I can do like this how can I get these data to store in the same table.

For Example, Education table has ID(Autonumberred), User ID, Degree, Major, University, Year and Honour.

When one user input their data like this

enter image description here

Suppose the User ID is 10000, then in the table should store like this...

(1)ID(Autonumberred), (2)User ID, (3)Degree, (4)Major, (5)University, (6)Year and (7)Honour.

(1)00001, (2)10000, (3)Master Degree, (4)Information Technology, (5)Assumption University, (6)2014, (7)None.

(1)00002, (2)10000, (3)Bachelor Degree, (4)Business Data Analysis, (5)Thammasat University, (6)2012, (7)Magna Cum Laude.

Thank you in advance.

Ala Alam Falaki
  • 345
  • 1
  • 9
  • 19
gznero
  • 193
  • 11
  • This could be a lot easier if you can use JavaScript. Since it's only tagged PHP are you looking for a pure PHP / HTML solution? – Chris Mar 26 '16 at 08:42
  • Nope, actually if JS can help, I appreciate it. I'm still new to PHP so I don't know how to use JS yet. – gznero Mar 26 '16 at 09:15

4 Answers4

0

For your first question:

When you want to name your input fields, use [], for example <input name="year[]" /> if you put it like this, after submitting the form, you get an array of all the inputs. put new inputs with a + button is just matter of JS codes to display new inputs.

And for your second question is just a matter of inserting data in to the database.

Ala Alam Falaki
  • 345
  • 1
  • 9
  • 19
0

First you can create your form on html similar this : http://1stwebdesigner.com/php-contact-form-html

Then, you must write a function with php, about press the + button create a new row in table and you can use php POST method for the send your form data a new php file and GET it.

0

You should use Javascript DOM for the task. What you are asking for is out of the scope of this site but you can learn Javascript here:http://www.w3schools.com/js/js_htmldom.asp

And for saving these data use multiple in input tag as in this example:Inserting multiple rows from a php form into the database

Community
  • 1
  • 1
Anish Silwal
  • 980
  • 1
  • 10
  • 24
0

$(document).ready(function() {
 $("#more").click(function() {
  $("#clone" ).clone().appendTo("#main_wrap");
 });
}); 
input{ width:200px; float:left;}select{ width:200px; float:left;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form action="submit.php" method="post">
<div style="width:250px;" id="main_wrap">
 <div id="clone" style="float:left; width:100%;">
  <select name="education[]">
   <option value="" selected="selected">Education</option>
   <option value="1">value 1</option>
   <option value="2">value 2</option>
   <option value="3">value 3</option>
  </select>
  <input type="text" name="in[]" placeholder='In'>
  <input type="text" name="from[]" placeholder='From'>
   <select name="year[]">
    <option value="" selected="selected"> Year</option>
    <option value="2013">2013</option>
    <option value="2014">2014</option>
    <option value="2015">2015</option>
   </select>
   </br>
 </div>
</div>
<div style="float:left;">
 <input type="button" value="more" id="more" style="float:left;">
</div>
<div style="float:left;">
 <input type="submit" value="Submit Form" style="float:left;">
</div>
</form>

And in your submit.php file use $_POST to get all the values and insert into db

<?php 
if(isset($_POST))
{
    echo "<pre>";
    print_r($_POST);
}   
?>
Manjeet Barnala
  • 2,975
  • 1
  • 10
  • 20