Title: form fillup html css php mysql
Tags: javascript;php;jquery;sql
Question: <html&gt;
<head&gt;

</head&gt;
<body&gt;
<a href=&quot;#&quot; id=&quot;filldetails&quot; onfocusout=&quot;addFields()&quot;&gt;<input type=&quot;text&quot; id=&quot;member&quot; name=&quot;member&quot; value=&quot;&quot;&gt;Number of members: (max. 10)<br /&gt;
Fill Details</a&gt;
<form class=&quot;contact-form row&quot; method=&quot;post&quot; action=&quot;test.php&quot; enctype=&quot;multipart/form-data&quot;&gt;
<div id=&quot;container&quot;&gt;</div&gt;

<div class=&quot;form-field col-lg-12&quot;&gt;
<input class=&quot;submit-btn&quot; type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;submit&quot;&gt;
</div&gt;
</form&gt;
</body&gt;
<?php
include('config.php');
if(isset($_POST['submit']))
$name = $_POST['member_name'.$i.''];
$sql=&quot;INSERT INTO `ssk`.`members` (`member_name`) VALUES ('$name')&quot;;
$query=mysql_query($sql,$con);
if($query)
echo '<div class=&quot;alert alert-success&quot;&gt;
<strong&gt;form submitted successfully your member-id is '.$member_id.' </strong&gt;
</div&gt;';?&gt;
<script&gt;
alert('Thank you! Your form has been submitted and is being verified please note-down the member-id.');
</script&gt;
<?php
}else{
echo '<div class=&quot;alert alert-success&quot;&gt;
<strong&gt;unsuccessful please read the above data and fill the form accordingly.</strong&gt;
</div&gt;';
?&gt;
<script&gt;
alert('ERROR:Request unprocessed');
</script&gt;
<?php
</html&gt;
What I want is to have a form which accepts the number of fields to be generated after which the user has to fill the generated input fields and the data has to be stored in the database is their any alternate way of doing this using PHP &amp; MYSQL its taking entry of first data bur not working dynamic please help me with this.
Comment: https://dcblog.dev/dynamic-form-elements-with-jquery

Comment: now i have placed the php code help me with this @NigelRen

Comment: What does your current code not do which you need it to do.  What efforts have you made to get it to work and the specific problems you have with it?

Here is the accepted answer: Using the structure you already have you could simply put a while loop in the php:
if(isset($_POST['submit']))
while(isset($_POST['member_name'.$i]))
$name = $_POST['member_name'.$i.''];
$sql = &quot;INSERT INTO `ssk`.`members` (`member_name`) VALUES ('$name')&quot;;
//rest of the code here
//increment $i
$i++;
You could also have used arrays for the form inputs e.g. input.name = &quot;member_name[]&quot; and then the loop in php could have have been foreach($_POST['member_name'] as $i=&gt;$name).
Please also look into validating the post variables and properly preparing sql statements so you are not open to sql injection or problems if the name contained a quote.
Comment for this answer: thank you for your answer it was really helpful finally succeeded after lot of efforts :)


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:08/15/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><php><jquery><sql>', 'Title': 'form fillup html css php mysql', 'ViewCount': 112, 'id': 63424514, 'user_AboutMe': '', 'user_AccountId': 13316577.0, 'user_DisplayName': 'khalandar bankapur', 'user_Reputation': 41.0, 'user_Views': 20.0, 'user_id': 9612800.0}}