Hello, I need help how to handling & insert the each values from this form below to mysql. I really have no idea. <html> <head> <title></title> <script language="javascript"> fields = 0; function addInput() { if (fields != 10) { document.getElementById('text').innerHTML += "<input type='text' value='' /><br />"; fields += 1; } else { document.getElementById('text').innerHTML += "<br />Only 10 upload fields allowed."; document.form.add.disabled=true; } } </script> </head> <body> <form name="form" method="post" action="engine/proc_add.php"> <input type="button" onclick="addInput()" name="add" value="Add input field" /> </form> <div id="text"> </div> </body> </html> HTML: Thank you for any help
You have closed the <form> tag before the start of your <DIV > tag that adds the text fields dynamically.. .Please try pasting the <div id="text"> </div> PHP: before the </form> tag and try again.
Change your code <html> <head> <title></title> <script language="javascript"> fields = 0; function addInput() { if (fields != 10) { document.getElementById('text').innerHTML += "<input type='text' name='text"+fields+"' value='' /><br />"; fields += 1; } else { document.getElementById('text').innerHTML += "<br />Only 10 upload fields allowed."; document.form.add.disabled=true; } } </script> </head> <body> <form name="form" method="post" action="engine/proc_add.php"> <input type="button" onclick="addInput()" name="add" value="Add input field" /> <div id="text"></div> </form> </body></html> In the file proc_add.php write <?php //open connection with mysql and select the database for($i=0$i<10;$i++) { $text=$_POST['text'.$i]; if($text!="") { //use the value in $text to add value to the fields. } } ?> I hope this sorts out your problem