SlideShare a Scribd company logo
In tutorial we will learn how to How to Dynamically Add /
Remove input fields in PHP with Jquery Ajax and insert data
in to the database.
First create a HTML form with one filed and a submit
button.
<form name="add_name" id="add_name" method="post">
<div class="table-responsive">
<table class="table table-bordered" id="dynamic_field">
<tr>
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
<td><input type="text" name="skill[]"
placeholder="Enter your Skill" class="form-control
name_list" /></td>
<td><button type="button" name="add" id="add"
class="btn btn-success">Add More</button></td>
</tr>
</table>
<input type="submit" name="submit" id="submit"
class="btn btn-info" value="Submit" />
</div>
</form>
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
<script> $(document).ready(function(){ var i=1;
$('#add').click(function(){ i++;
$('#dynamic_field').append('<tr
id="row'+i+'"><td><input type="text"
name="skill[]" placeholder="Enter your Skill"
class="form-control name_list"
/></td><td><button type="button"
name="remove" id="'+i+'" class="btn btn-danger
btn_remove">X</button></td></tr>'); });
$(document).on('click', '.btn_remove', function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove(); }); }); </script>
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
CREATE TABLE `tblskills` ( `id` int(11) NOT NULL, `skill`
varchar(250) NOT NULL ) ENGINE=MyISAM DEFAULT
CHARSET=latin1;
Create database connection file (config.php)
<?php
define('DB_SERVER','localhost');
define('DB_USER','root');
define('DB_PASS' ,'');
define('DB_NAME', 'practice');
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
$con =
mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_
NAME);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " .
mysqli_connect_error();
}
?>
Code for Data insertion into the database.
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
<?php
//Databse connection file
include('config.php');
if(isset($_POST['submit']))
{
// Counting No fo skilss
$count = count($_POST["skill"]);
//Getting post values
$skill=$_POST["skill"];
if($count > 1)
{
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
for($i=0; $i<$count; $i++)
{
if(trim($_POST["skill"][$i] != ''))
{
$sql =mysqli_query($con,"INSERT INTO
tblskills(skill) VALUES('$skill[$i]')");
}
}
echo "<script>alert('Skills inserted
successfully');</script>";
}
else
{
echo "<script>alert('Please enter skill');</script>";
}
}
?>
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
<?php
//Database connection file
include('config.php');
if(isset($_POST['submit']))
{
// Counting No fo skilss
$count = count($_POST["skill"]);
//Getting post values
$skill=$_POST["skill"];
if($count > 1)
{
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
for($i=0; $i<$count; $i++)
{
if(trim($_POST["skill"][$i] != ''))
{
$sql =mysqli_query($con,"INSERT INTO
tblskills(skill) VALUES('$skill[$i]')");
}
}
echo "<script>alert('Skills inserted
successfully');</script>";
}
else
{
echo "<script>alert('Please enter skill');</script>";
}
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
}
?>
<html>
<head>
<title>PHPGurukul Programmin Blog | Dynamically
Add or Remove input fields in PHP with
JQuery</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstr
ap/3.3.6/css/bootstrap.min.css" />
<script
src="https://maxcdn.bootstrapcdn.com/bootstra
p/3.3.6/js/bootstrap.min.js"></script>
<script
src="https://ajax.googleapis.com/ajax/libs/jque
ry/2.2.0/jquery.min.js"></script>
</head>
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
<body>
<div class="container">
<h2 align="center">Dynamically Add or
Remove input fields in PHP with
JQuery</h2><br />
<div class="form-group">
<form name="add_name" id="add_name"
method="post">
<div class="table-responsive">
<table class="table table-bordered"
id="dynamic_field">
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
<tr>
<td><input type="text" name="skill[]"
placeholder="Enter your Skill" class="form-
control name_list" /></td>
<td><button type="button" name="add"
id="add" class="btn btn-success">Add
More</button></td>
</tr>
</table>
<input type="submit" name="submit"
id="submit" class="btn btn-info"
value="Submit" />
</div>
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
</form>
</div>
</div>
</body>
<script>
$(document).ready(function(){
var i=1;
$('#add').click(function(){
i++;
$('#dynamic_field').append('<tr
id="row'+i+'"><td><input type="text"
name="skill[]" placeholder="Enter your Skill"
class="form-control name_list"
/></td><td><button type="button"
name="remove" id="'+i+'" class="btn btn-danger
btn_remove">X</button></td></tr>');
});
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
<td><button type="button" name="remove"
id="'+i+'" class="btn btn-danger
btn_remove">X</button></td></tr>');
});
$(document).on('click', '.btn_remove',
function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove();
});
});
</script>
</html>
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/
For More Info Visit:
https://phpgurukul.com/how-to-dynamically-
add-remove-input-fields-in-php-with-
jquery-ajax/
https://phpgurukul.com/how-to-
dynamically-add-remove-input-
fields-in-php-with-jquery-ajax/

More Related Content

What's hot

Javascript validating form
Javascript validating formJavascript validating form
Javascript validating form
Jesus Obenita Jr.
 
[ WrocLoveRb 2012] user perspective testing using ruby
[ WrocLoveRb 2012] user perspective testing using ruby[ WrocLoveRb 2012] user perspective testing using ruby
[ WrocLoveRb 2012] user perspective testing using ruby
Mikstura.IT Foundation | Web & Mobile Community
 
Master AngularJS
Master AngularJSMaster AngularJS
Master AngularJS
Fabien Vauchelles
 
카카오커머스를 지탱하는 Angular
카카오커머스를 지탱하는 Angular카카오커머스를 지탱하는 Angular
카카오커머스를 지탱하는 Angular
if kakao
 
Jsf lab
Jsf labJsf lab
Jsf lab
Yu-Ting Chen
 
Documentation For Tab Setup
Documentation For Tab SetupDocumentation For Tab Setup
Documentation For Tab Setup
vkeeton
 
Borrador del blog
Borrador del blogBorrador del blog
Borrador del blog
Sena Cedagro
 
Creating web api and consuming part 2
Creating web api and consuming part 2Creating web api and consuming part 2
Creating web api and consuming part 2
Dipendra Shekhawat
 
Intro to Haml
Intro to HamlIntro to Haml
Intro to Haml
Clifford Heath
 

What's hot (9)

Javascript validating form
Javascript validating formJavascript validating form
Javascript validating form
 
[ WrocLoveRb 2012] user perspective testing using ruby
[ WrocLoveRb 2012] user perspective testing using ruby[ WrocLoveRb 2012] user perspective testing using ruby
[ WrocLoveRb 2012] user perspective testing using ruby
 
Master AngularJS
Master AngularJSMaster AngularJS
Master AngularJS
 
카카오커머스를 지탱하는 Angular
카카오커머스를 지탱하는 Angular카카오커머스를 지탱하는 Angular
카카오커머스를 지탱하는 Angular
 
Jsf lab
Jsf labJsf lab
Jsf lab
 
Documentation For Tab Setup
Documentation For Tab SetupDocumentation For Tab Setup
Documentation For Tab Setup
 
Borrador del blog
Borrador del blogBorrador del blog
Borrador del blog
 
Creating web api and consuming part 2
Creating web api and consuming part 2Creating web api and consuming part 2
Creating web api and consuming part 2
 
Intro to Haml
Intro to HamlIntro to Haml
Intro to Haml
 

Similar to How to dynamically add remove input fields in php with jquery ajax

Hello I need help getting my delete and additem button to work- The de.pdf
Hello I need help getting my delete and additem button to work- The de.pdfHello I need help getting my delete and additem button to work- The de.pdf
Hello I need help getting my delete and additem button to work- The de.pdf
Ian0J2Bondo
 
Database connectivity in PHP
Database connectivity in PHPDatabase connectivity in PHP
Database connectivity in PHP
Vineet Kumar Saini
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in php
herat university
 
phptut2
phptut2phptut2
phptut2
tutorialsruby
 
phptut2
phptut2phptut2
phptut2
tutorialsruby
 
phptut2
phptut2phptut2
phptut2
tutorialsruby
 
phptut2
phptut2phptut2
phptut2
tutorialsruby
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
Maitree Patel
 
Kohana bootstrap - modal form
Kohana   bootstrap - modal formKohana   bootstrap - modal form
Kohana bootstrap - modal form
Julio Pari
 
Kohana bootstrap - modal form
Kohana   bootstrap - modal formKohana   bootstrap - modal form
Kohana bootstrap - modal form
Julio Pari
 
HTML SERVER CONTROL - ASP.NET WITH C#
HTML SERVER CONTROL  - ASP.NET WITH C#HTML SERVER CONTROL  - ASP.NET WITH C#
HTML SERVER CONTROL - ASP.NET WITH C#
priya Nithya
 
Lect# 1 html part ii
Lect# 1 html part iiLect# 1 html part ii
Lect# 1 html part ii
MuhammadAbdulSattarC
 
Intro to Jinja2 Templates - San Francisco Flask Meetup
Intro to Jinja2 Templates - San Francisco Flask MeetupIntro to Jinja2 Templates - San Francisco Flask Meetup
Intro to Jinja2 Templates - San Francisco Flask Meetup
Alan Hamlett
 
Lab final
Lab finalLab final
Fcr 2
Fcr 2Fcr 2
Fcr 2
Ravi Peter
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-Kjaer
COMMON Europe
 
Your Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages SuckYour Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages Suck
Anthony Montalbano
 
Why study java script
Why study java scriptWhy study java script
Why study java script
dharmendra kumar
 
Ex[1].3 php db connectivity
Ex[1].3 php db connectivityEx[1].3 php db connectivity
Ex[1].3 php db connectivity
Mouli Chandira
 
Html To JSP
Html To JSPHtml To JSP
Html To JSP
PlanetB4U
 

Similar to How to dynamically add remove input fields in php with jquery ajax (20)

Hello I need help getting my delete and additem button to work- The de.pdf
Hello I need help getting my delete and additem button to work- The de.pdfHello I need help getting my delete and additem button to work- The de.pdf
Hello I need help getting my delete and additem button to work- The de.pdf
 
Database connectivity in PHP
Database connectivity in PHPDatabase connectivity in PHP
Database connectivity in PHP
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in php
 
phptut2
phptut2phptut2
phptut2
 
phptut2
phptut2phptut2
phptut2
 
phptut2
phptut2phptut2
phptut2
 
phptut2
phptut2phptut2
phptut2
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
 
Kohana bootstrap - modal form
Kohana   bootstrap - modal formKohana   bootstrap - modal form
Kohana bootstrap - modal form
 
Kohana bootstrap - modal form
Kohana   bootstrap - modal formKohana   bootstrap - modal form
Kohana bootstrap - modal form
 
HTML SERVER CONTROL - ASP.NET WITH C#
HTML SERVER CONTROL  - ASP.NET WITH C#HTML SERVER CONTROL  - ASP.NET WITH C#
HTML SERVER CONTROL - ASP.NET WITH C#
 
Lect# 1 html part ii
Lect# 1 html part iiLect# 1 html part ii
Lect# 1 html part ii
 
Intro to Jinja2 Templates - San Francisco Flask Meetup
Intro to Jinja2 Templates - San Francisco Flask MeetupIntro to Jinja2 Templates - San Francisco Flask Meetup
Intro to Jinja2 Templates - San Francisco Flask Meetup
 
Lab final
Lab finalLab final
Lab final
 
Fcr 2
Fcr 2Fcr 2
Fcr 2
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-Kjaer
 
Your Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages SuckYour Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages Suck
 
Why study java script
Why study java scriptWhy study java script
Why study java script
 
Ex[1].3 php db connectivity
Ex[1].3 php db connectivityEx[1].3 php db connectivity
Ex[1].3 php db connectivity
 
Html To JSP
Html To JSPHtml To JSP
Html To JSP
 

Recently uploaded

Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 

Recently uploaded (20)

Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 

How to dynamically add remove input fields in php with jquery ajax

  • 1. In tutorial we will learn how to How to Dynamically Add / Remove input fields in PHP with Jquery Ajax and insert data in to the database. First create a HTML form with one filed and a submit button. <form name="add_name" id="add_name" method="post"> <div class="table-responsive"> <table class="table table-bordered" id="dynamic_field"> <tr> https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 2. <td><input type="text" name="skill[]" placeholder="Enter your Skill" class="form-control name_list" /></td> <td><button type="button" name="add" id="add" class="btn btn-success">Add More</button></td> </tr> </table> <input type="submit" name="submit" id="submit" class="btn btn-info" value="Submit" /> </div> </form> https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 3. <script> $(document).ready(function(){ var i=1; $('#add').click(function(){ i++; $('#dynamic_field').append('<tr id="row'+i+'"><td><input type="text" name="skill[]" placeholder="Enter your Skill" class="form-control name_list" /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>'); }); $(document).on('click', '.btn_remove', function(){ var button_id = $(this).attr("id"); $('#row'+button_id+'').remove(); }); }); </script> https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 4. CREATE TABLE `tblskills` ( `id` int(11) NOT NULL, `skill` varchar(250) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Create database connection file (config.php) <?php define('DB_SERVER','localhost'); define('DB_USER','root'); define('DB_PASS' ,''); define('DB_NAME', 'practice'); https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 5. $con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_ NAME); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?> Code for Data insertion into the database. https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 6. <?php //Databse connection file include('config.php'); if(isset($_POST['submit'])) { // Counting No fo skilss $count = count($_POST["skill"]); //Getting post values $skill=$_POST["skill"]; if($count > 1) { https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 7. for($i=0; $i<$count; $i++) { if(trim($_POST["skill"][$i] != '')) { $sql =mysqli_query($con,"INSERT INTO tblskills(skill) VALUES('$skill[$i]')"); } } echo "<script>alert('Skills inserted successfully');</script>"; } else { echo "<script>alert('Please enter skill');</script>"; } } ?> https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 8. <?php //Database connection file include('config.php'); if(isset($_POST['submit'])) { // Counting No fo skilss $count = count($_POST["skill"]); //Getting post values $skill=$_POST["skill"]; if($count > 1) { https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 9. for($i=0; $i<$count; $i++) { if(trim($_POST["skill"][$i] != '')) { $sql =mysqli_query($con,"INSERT INTO tblskills(skill) VALUES('$skill[$i]')"); } } echo "<script>alert('Skills inserted successfully');</script>"; } else { echo "<script>alert('Please enter skill');</script>"; } https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 10. } ?> <html> <head> <title>PHPGurukul Programmin Blog | Dynamically Add or Remove input fields in PHP with JQuery</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstr ap/3.3.6/css/bootstrap.min.css" /> <script src="https://maxcdn.bootstrapcdn.com/bootstra p/3.3.6/js/bootstrap.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jque ry/2.2.0/jquery.min.js"></script> </head> https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 11. <body> <div class="container"> <h2 align="center">Dynamically Add or Remove input fields in PHP with JQuery</h2><br /> <div class="form-group"> <form name="add_name" id="add_name" method="post"> <div class="table-responsive"> <table class="table table-bordered" id="dynamic_field"> https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 12. <tr> <td><input type="text" name="skill[]" placeholder="Enter your Skill" class="form- control name_list" /></td> <td><button type="button" name="add" id="add" class="btn btn-success">Add More</button></td> </tr> </table> <input type="submit" name="submit" id="submit" class="btn btn-info" value="Submit" /> </div> https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 13. </form> </div> </div> </body> <script> $(document).ready(function(){ var i=1; $('#add').click(function(){ i++; $('#dynamic_field').append('<tr id="row'+i+'"><td><input type="text" name="skill[]" placeholder="Enter your Skill" class="form-control name_list" /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>'); }); https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 14. <td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>'); }); $(document).on('click', '.btn_remove', function(){ var button_id = $(this).attr("id"); $('#row'+button_id+'').remove(); }); }); </script> </html> https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/
  • 15. For More Info Visit: https://phpgurukul.com/how-to-dynamically- add-remove-input-fields-in-php-with- jquery-ajax/ https://phpgurukul.com/how-to- dynamically-add-remove-input- fields-in-php-with-jquery-ajax/