Ajax Tutorial
- What is Ajax
- How Ajax Work
- ajax() and load() Function
- AJAX get() and post() Methods
- AJAX Function
- Ajax Success
- Ajax Button Click
- Ajax div load on button click
- Insert Data
- Delete Data
- User Registration
- ContactUs Form
- Check existing Password in Ajax and change the Password
- Ajax Search
- Ajax Serialize Insert
- Ajax without Searialize Insert
- Ajax User Check Availability
- Ajax OptionBox
- Ajax Dropdown Session
- dynamic text box Add/Remove
- Star Rating
- Pin Check Available
- Ajax Programs
- Clear Form Field after submitting form
- Loader load show / hide
- Multiple Functions
Customer Say
How to insert select option data in database in php using ajax.
How to insert select option data in database in php using ajax.
File name : index.php
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('select[name="ops"]').change(function(){
var status = $(this).val();
$.ajax({
type: 'POST',
url: 'ajax-insert.php',
data: {getStatus: status},
dataType: 'html',
success:function(data) {
$('#stage').html(data);
}
});
});
});
</script>
</head>
<body>
<select name="ops" id="ops">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
<option value="4">D</option>
<option value="5">E</option>
</select>
<div id="stage"></div>
</body>
</html>
ajax-insert.php
File name : ajax-insert.php
<?php
include 'db.php';
$opt = $_POST['getStatus'];
//echo $opt;
$qry = "insert into option_table (opvalue) values('$opt')";
$result = mysqli_query($conn, $qry);
if($result > 0)
{
echo "Record inserted successfully";
}
?>
File name : index.php
File name : index.php
File name : index.php
File name : index.php
File name : index.php
File name : index.php