subjects
course
chapters
I want to add 2 dynamic dropdown lists, one is for subjects, and one is for course. When I select subject, courses which is added to that subject should be loaded in the course dropdown list, and then add chapters to that courses.
How do I do that?
Any help would be appreciated.
Here is my code:
<div class="content-form-inner">
<div id="page-heading">Enter the details</div>
<div class="form_loader" id="thisFormLoader"></div>
<div id="error_message"></div>
<form name="thisForm" id="thisForm" action="editchapters.php?mode=<?php echo $_REQUEST['mode']; ?>&id=<?php echo $id; ?>" method="post" enctype="multipart/form-data">
<table border="0" cellpadding="0" cellspacing="0" id="id-form" >
<tr>
<th valign="top" style="width:0%"><span class="required">*</span>Subject</th>
<td style="width: 0%">
<select name="subject_name" class="select-form required " style="color:#000 !important;width:200px !important">
<option value="">Select</option>
<?php
$sql = "select * from mock_subject ";
$res = mysqli_query($dbhandle,$sql);
$numrows =mysqli_num_rows($res);
echo mysql_error();
if($numrows){
while($obj = mysqli_fetch_object($res)){
if($obj->status == 1){
if($subject == $obj->id){
echo '<option value="'.$obj->id.'" selected>'.($obj->subject_name).'</option>';
}
else{
echo '<option value="'.$obj->id.'">'.($obj->subject_name).'</option>';
}
}
}
}
?>
</select>
</td>
<td style="width: 0%;">
<div id="subject_id-error" class="error-inner"></div>
</td>
<td></td>
</tr>
<tr>
<th valign="top" style="width:0%"><span class="required">*</span>Course</th>
<td style="width: 0%">
<select name="course_name" class="select-form required " style="color:#000 !important;width:200px !important">
<option value="">Select</option>
<?php
$sql = "select * from mock_course ";
$res = mysqli_query($dbhandle,$sql);
$numrows =mysqli_num_rows($res);
echo mysql_error();
if($numrows){
while($obj = mysqli_fetch_object($res)){
if($obj->status == 1){
if($course == $obj->id){
echo '<option value="'.$obj->id.'" selected>'.($obj->course_name).'</option>';
}
else{
echo '<option value="'.$obj->id.'">'.($obj->course_name).'</option>';
}
}
}
}
?>
</select>
</td>
<td style="width: 0%;">
<div id="course_id-error" class="error-inner"></div>
</td>
<td></td>
</tr>
<tr>
<th><span class="required">*</span>Chapter</th>
<td><input type="text" name="chapter_name" class="inp-form required" value="<?php echo $chapter;?>" style="color:#000 !important;"></td>
<td>
<div></div>
</td>
</tr>
<tr>
<th> </th>
<td valign="top"><input type="submit" name="submit_button" value="<?php echo $mode=="edit"? "Update" : "Add" ?>" class="form-submit" />
<input type="reset" value="Reset" class="form-reset" />
</tr>
</table>
</form>
<div class="clear"></div>
</div>
One possible solution would, if your data set is comparatively small. Load all the data on page load, and use jquery to get value of dropdown, and based on that formulate the values for the other drop downs.
Second Solution would be to us AJAX and call data from your database for every action. and print using Angular.
I've attached a sample code for that.
This is my_script.js
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$(document).ready(function(){
callSetTimeout();
});
function callSetTimeout(){
setTimeout(function(){
update();
callSetTimeout();
},200);
}
function update(){
$http.get("http://localhost/WhatsOnYourMInd/db.php")
.success(function (response) {$scope.names = response.records;});
}
});
This is for db.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mind";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM data";
$result = $conn->query($sql);
$jsonString=array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
array_push($jsonString,array('id' =>$row['id'],'name' =>$row['name'],'message' =>$row['message']));
}
echo json_encode(array("records"=>$jsonString));
} else {
echo "0 results";
}
$conn->close();
?>
This is for index.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Whats on your Mind</title>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
<ul id="ajax"></ul>
<div ng-app="myApp" ng-controller="customersCtrl">
<ol>
<li ng-repeat="x in names">
{{ 'Id:'+x.id + ' Name:' + x.name +' Message:'+x.message}}
</li>
</ol>
</div>
<script src="my_script.js"></script>
</body>
</html>
Easiest way of creating dynamic dropdown is by using jquery inside the head tag.
Give onchange() event and guide the data to another page using jquery code, and then link 2 dropdowns. The code I did is like this, which I felt is the easiest way for dynamic dropdowns.
jquery which I included is
<script>
function ajaxDrp(data){
$.ajax({
method: "POST",
url: "chapterDropdown.php",
data: {
id: data
}
}).success(function(data) {
$('#selectCourse').empty();
$('#selectCourse').append(data);
});
}
</script>
#selectCourse is the id I have given to the other dropdown which have to be in sync with the first dropdown.
The given url in the jquery is the path where data of first dropdown is getting collected. In my case, the code is like this:
<?php
$id = $_REQUEST['id'];
$query = "SELECT * FROM `your table name` WHERE subject_id = " . $id;
$result = mysqli_query($dbhandle,$query);
$count = 0;
$option`enter code here` = '';
while($row = mysqli_fetch_assoc($result)) {
$option .= '<option
value="'.$row['id'].'">'.$row['course_name'].'</option>';
}
echo $option;
?>
Related
I'm doing a car dealership website where I have to fetch cars from database and enable user search form by multiple criteria (brand, model, energy). Depending on the selection, on the same page the list of all the cars matching this criteria appears in the form of table, and clicking on one of the cars opens a new page where all the available information about the car are shown. The form method is POST, and I'm having trouble passing the id variable onto a new page where I could search the database based on that car id and list the information.
My JQUERY code is as follows:
<script type="text/javascript">
$(document).ready(function(){
$('#car').on('change',function(){
var carID = $(this).val();
if(carID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'marque_id='+carID,
success:function(html){
$('#test1').html(carID);
$('#model').removeAttr("disabled");
$('#model').html(html);
}
});
}else{
$('#model').attr("disabled");
$('#energy').attr("disabled");
}
});
$('#model').on('change',function(){
var modelID = $(this).val();
if(modelID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'modele_id='+modelID,
success:function(html){
$('#test').html(modelID);
$('#energy').removeAttr("disabled");
$('#energy').html(html);
}
});
}else{
$('#energy').attr("disabled");
}
});
$('tr[data-href]').on("click", function() {
document.location = $(this).data('href');
});
});
</script>
Form search code:
<form method="post" name="form">
<div class="select-boxes">
<?php
//Include database configuration file
include('dbConfig.php');
//Get all car data
$query = $db->query("SELECT marque_name,marque_id FROM vehicule_marque order by marque_name");
//Count total number of rows
$rowCount = $query->num_rows;
$car = isset($_POST['car']) ? $_POST['car'] : '';
$model = isset($_POST['model']) ? $_POST['model'] : '';
$energy = isset($_POST['energy']) ? $_POST['energy'] : '';
?>
<div>Select car</div>
<select name="car" id="car" >
<option value="">Select Car</option>
<?php
if($rowCount > 0){
while($row = $query->fetch_assoc()){
echo '<option value="'.$row['marque_id'].'">'.$row['marque_name'].'</option>';
}
}else{
echo '<option value="">Car not available</option>';
}
?>
</select>
<div id="test1"></div>
<div>Select car model</div>
<select name="model" id="model" disabled>
<option value=""><!--Select car first--></option>
</select>
<div id="test"></div>
<div>Select energy</div>
<select name="energy" id="energy" disabled>
<option value=""><!--Select model first--></option>
</select>
<input type="submit" name="submit" value="submit">
</div>
</form>
<form id="form1" name="form1" method="post">
<div class="well">
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Picture</th>
<th>Marque</th>
<th>Model</th>
<th>Energy</th>
<th>KM</th>
<th>Price</th>
<th style="width: 26px;"></th>
</tr>
</thead>
<tbody>
<?php
$query2 = $db->query("SELECT reference_id, marque_name, modele_name, energie_name, vehicule_kilometrage, vehicule_price_ttc FROM vehicule AS a INNER JOIN vehicule_marque AS b INNER JOIN vehicule_modele AS c INNER JOIN vehicule_energie AS d WHERE a.marque_id = '".$car."' AND a.modele_id = '".$model."' AND a.energie_id = '".$energy."' AND b.marque_id = a.marque_id AND c.modele_id = a.modele_id AND d.energie_id = a.energie_id");
$rowCount2 = $query2->num_rows;
if($rowCount2>0){
while($myrow = $query2->fetch_assoc()){
?>
<tr data-href="results.php?id=">
<td><?php echo $myrow["reference_id"]; ?></td>
<td><img src="<?php echo 'images/' ?>"</td>
<td><?php echo $myrow["marque_name"]; ?></td>
<td><?php echo $myrow["modele_name"]; ?></td>
<td><?php echo $myrow["energie_name"]; ?></td>
<td><?php echo $myrow["vehicule_kilometrage"]; ?></td>
<td><?php echo $myrow["vehicule_price_ttc"]; ?> €</td>
</tr>
<?php
}
}else {
echo 'Error';
}
?>
</tbody>
</table>
</div>
</form>
Everything works correctly, the only problem I have is that I'm not sure how to get the $myrow["reference_id"] and append it to results.php?id= so I could show the information on that car on the new page using a new query.
Have you tried this?
<tr data-href="results.php?id=<?php echo $myrow["reference_id"]?>">
Would probably be cleaner to create the whole link as a string beforehand, and then echoing that string.
After php and mysql outputs a list of data in a table with radio buttons, dropdown boxes and text boxes for each row from the database, I'd like to be able to AJAX update the database onclick of radio button, dropdown boxes or entry of text. This is what I have...
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<?php
require_once 'config.php';
echo '<table style="margin:0 auto;">
<tr>
</tr>';
$sql = "SELECT id, address, suburb, lat, lng, day, date, time FROM addresses";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo '<tr>
<td><span style="font-weight:bold;">'. $row["address"].' '. $row["suburb"].'</span> <button style="float:right;" type="button">Go</button><br><br>
H<input type="radio" name="home['. $row["id"].']" value="1"/>
NH<input type="radio" name="home['. $row["id"].']" value="2"/>
<select style="padding:1.4px;">
<option></option>
<option>Mo</option>
<option>Tu</option>
<option>We</option>
<option>Th</option>
<option>Fr</option>
<option>Sa</option>
<option>Su</option>
</select>
<input type="text" name="time1" size="2">
<select style="padding:1.4px;">
<option></option>
<option>Mo</option>
<option>Tu</option>
<option>We</option>
<option>Th</option>
<option>Fr</option>
<option>Sa</option>
<option>Su</option>
</select>
<input type="text" name="time2" size="2"><br>
<input style="width:100%; margin-top:5px;" type="text" name="notes" placeholder="Add note">
<br><br>
</td>
<td>
</td>
</tr>';
}
} else {
echo "0 results";
}
echo '</table>';
$conn->close();
?>
<script>
$(document).ready(function(){
$('input[type="radio"]').click(function(){
var home = $(this).val();
$.ajax({
url:"updateaddress.php",
method:"POST",
data:{home:home},
});
});
});
</script>
<?php
// Include config file
require_once 'config.php';
$id = mysqli_real_escape_string($conn, $_POST['id']);
$home = mysqli_real_escape_string($conn, $_POST['home']);
if(isset($_POST["home"])) {
$sql = "UPDATE addresses SET home='$home' WHERE id=$id";
if($conn->query($sql) === TRUE){
} else {
echo "error" . $sql . "<br>".$conn->error;
}
}
mysqli_close($conn);
header("Location: {$_SERVER['HTTP_REFERER']}");
exit;
?>
I can't figure out what I need to do to get this to work.
Please help.
You need to pass the id of the row in to that ajax page...
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<?php
require_once 'config.php';
echo '<table style="margin:0 auto;">
<tr>
</tr>';
$sql = "SELECT id, address, suburb, lat, lng, day, date, time FROM addresses";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo '<tr>
<td><span style="font-weight:bold;">'. $row["address"].' '. $row["suburb"].'</span> <button style="float:right;" type="button">Go</button><br><br>
H<input type="radio" name="home['. $row["id"].']" id="'. $row["id"].'" value="1"/>
NH<input type="radio" name="home['. $row["id"].']" id="'. $row["id"].'" value="2"/>
<select style="padding:1.4px;">
<option></option>
<option>Mo</option>
<option>Tu</option>
<option>We</option>
<option>Th</option>
<option>Fr</option>
<option>Sa</option>
<option>Su</option>
</select>
<input type="text" name="time1" size="2">
<select style="padding:1.4px;">
<option></option>
<option>Mo</option>
<option>Tu</option>
<option>We</option>
<option>Th</option>
<option>Fr</option>
<option>Sa</option>
<option>Su</option>
</select>
<input type="text" name="time2" size="2"><br>
<input style="width:100%; margin-top:5px;" type="text" name="notes" placeholder="Add note">
<br><br>
</td>
<td>
</td>
</tr>';
}
} else {
echo "0 results";
}
echo '</table>';
$conn->close();
?>
<script>
$(document).ready(function(){
$('input[type="radio"]').click(function(){
var home = $(this).val();
var id = $(this).attr('id');
$.ajax({
url:"updateaddress.php",
method:"POST",
data:{home:home,id:id},
});
});
});
</script>
<?php
// Include config file
require_once 'config.php';
$id = mysqli_real_escape_string($conn, $_POST['id']);
$home = mysqli_real_escape_string($conn, $_POST['home']);
if(isset($_POST["home"])) {
$sql = "UPDATE addresses SET home='$home' WHERE id=$id";
if($conn->query($sql) === TRUE){
} else {
echo "error" . $sql . "<br>".$conn->error;
}
}
mysqli_close($conn);
header("Location: {$_SERVER['HTTP_REFERER']}");
exit;
?>
I am getting $pgcode value required for the second select option but the form is refreshed which I do not want. I also tried adding some html divs but in that case the form is duplicating some content and also refreshing.
How can I make this work without a refresh occurring?
<?php
if (session_id() == '') {
session_start();
ob_start();
}
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
include("dbc.php");
if (isset($_POST['model'])) {
$pgcode = $_POST['model'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script>
$('#dataTable').on('change','.select-desc',function(){
var cur_val = $(this).val();
$.ajax({
method:"POST",
url:"cashtran.php",
data:{model:cur_val},
success:function(result){
$('body').html(result);
},
});
});
});
</script>
</head>
<body id="top">
<br class="clear" />
<div class="wrapper col4">
<div id="container">
<div id="content">
<form method="post" name="frmcashtran" action="">
<h3><span class="orange">Cash Payment Details</span></h3>
<fieldset>
<table>
<tr>
<td><input type="button" value="Add Row" id="addRow" /></td>
<td><input type="button" value="Remove Row" id="deleteRow"/></td>
</tr>
</table>
<table id="dataTable" border="0">
<tr>
<td></td>
<td><label>Main A/c</label></td>
<td><label>Subledger</label></td>
<td><label>Narration</label></td>
<td><label>Amount</label></td>
</tr>
<tr>
<td>
<?php
$sql = "SELECT gcode,acname FROM account ";
$result = mysqli_query($conn, $sql) or die(mysqli_error());
echo "<select name='acname[]' class='select-desc' tabindex='2'>";
echo "<option value=''>-- Select Main A/c --</option>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value = '{$row['gcode']}'";
if ($pgcode == $row['gcode'])
echo "selected = 'selected'";
echo ">{$row['acname']}</option>";
}
echo "</select>";
?>
</td>
<td>
<?php
$sql = "SELECT scode,sname FROM subldg where gcode='$pgcode' ";
$result = mysqli_query($conn, $sql) or die(mysqli_error());
echo "<select name='slname[]' tabindex='2'>";
echo "<option value=''>-- Select Subledger--</option>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value = '{$row['scode']}'";
if ($pscode == $row['scode'])
echo "selected = 'selected'";
echo ">{$row['sname']}</option>";
}
echo "</select>";
?>
</td>
</table>
</form>
</body>
</html>
If the entire page is being sent back as the response to the ajax request change the following PHP code
if (isset($_POST['model'])) {
$pgcode = $_POST['model'];
}
to
if( isset( $_POST['model'] ) ) {
ob_clean();
$pgcode = $_POST['model'];
exit( $pgcode );
}
I am trying to populate Material Description from the Material Number. Bot hte values are stored in same SQL tasble. So what I want when I select Material Maiterial Description shpul auto populate.
Fileds in table are Material & MaterialDescripotion
Below is code in in main file where data is fetched
<?php
include_once "dbConnect.php";
$sql = "SELECT * FROM DRLINK";
$result2 = mysqli_query($conn, $sql);
if (!$result2) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
$options = "";
while($row2 = mysqli_fetch_array($result2))
{
$options = $options."<option>$row2[1]</option>";
}
?>
<html>
<!DOCTYPE html>
<head>
<title>Dropdown Ajax</title>
</head>
<body>
<form action ="DSSTRsubmit.php" method="POST">
<table border="1">
<tr>
<td>Select Retailer</td>
</tr>
<tr>
<td>
<?php
echo "<select>";
echo $options;
echo "</select>";
?>
</td>
</tr>
</table>
<br/>
<br/>
<br/>
<table border="1">
<tr>
<td>Material</td>
<td>Material Description</td>
<td>Quantity</td>
<td>Unit of Measure</td>
</tr>
<tr>
<td>
<div class="Material">
<select name="Material" onchange="getId(this.value);">
<option value="">Select Country</option>
<?php
$query ="SELECT * FROM MATERIALLIST";
$results = mysqli_query($conn, $query);
foreach($results as $MATERIALLIST) {
?>
<option value="<?php echo $MATERIALLIST["Material"];?>"><?php echo $MATERIALLIST["Material"];?></option>
<?php
}
?>
</select>
</div>
</td>
<td>
<div class="MaterialDescription">
<select name="MaterialDescription" id="DesList">
<option value=""></option>
</select>
</div>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script>
function getId(val){
$.ajax({
type:"POST",
url:"getdata1.php",
data:"Material="+val,
success: function(data){
$("#DesList").html(data);
}
});
}
</script>
</td>
<td><input type="text" name="dquantity_name" /> </td>
<td><input type="text" name="duom_name" /> </td>
</tr>
</table>
<legend> </legend>
<p> <button type="submit" class="pure-button pure-button-primary">Send Stock</button>
<br>
<br>
<?php
echo "Distributor Page";
?>
</body>
</html>
below is the getdata1.php
<?php
include_once "dbConnect.php";
if(!empty($_POST["Material"])){
$Material= $_POST["Material"];
$query = "SELECT * FROM MATERIALLIST WHERE Material = $Material";
$results = mysqli_query($conn,$query);
foreach($results as $MaterialDescription){
?>
<option value="<?php echo $Des["Material"];?>"><?php echo $materialDescription ["MaterialDescription"];?></option>
<?php
}
}
?>
Iam able to select the material but on selection of material no material description auto populates.
Thanks for the help
PHP is case sensitive. Be careful about naming variables.
foreach contains upper case variable, while echo - lowercase. Also in echo you have space after variable and before opening bracket.
$MaterialDescription
$materialDescription_["MaterialDescription"]
Whenever the hyperlink with the yes id is clicked i dont want the page to refresh and then show the status, i want the status to change instant without page refreshing. I know Ajax deals with this, but can anyone provide me with a working example with my code please? As it melting my head :/
<h3 class="page-header"> Enquiries </h3>
<form id="enquiry" method="post" action="enquiry_csv.php">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th> First Name</th>
<th> Last Name</th>
<th>Email</th>
<th>Message</th>
<th>Date</th>
<th>Responded to Enquiry?</th>
<th>Status</th>
<th></th>
<th><input class='btn-success' name='export' id='btnExport' type='submit' value='Export to CSV'/></th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM enquiries";
$select_enquiries = mysqli_query($connection,$query);
while($row = mysqli_fetch_assoc($select_enquiries)) {
$Enquiry_ID = $row['Enquiry_ID'];
$FirstName = $row['First_Name'];
$LastName =$row['Last_Name'];
$Email = $row['Email'];
$Message = $row['Message'];
$Date =$row['Date'];
$Responded =$row['Responded'];
echo "<tr>";
echo "<td>$FirstName </td>";
echo "<td>$LastName </td>";
echo "<td>$Email </td>";
echo "<td>$Message </td>";
echo "<td>$Date </td>";
echo "<td> <a id='yes' class='success' style='' href='enquiries.php?Yes=$Enquiry_ID'>Yes</a> | <a class='success' href='enquiries.php?No=$Enquiry_ID'>No</a> </td>";
echo "<td> $Responded</td>";
echo "<td> <a class='btn btn-danger' href ='enquiries.php?delete=$Enquiry_ID'>Delete</a> </td>";
echo "</tr>";
}
?>
<?php
if(isset($_GET['Yes'])){
$enquiry_id = $_GET['Yes'];
$query = "UPDATE enquiries SET Responded = 'Yes' WHERE Enquiry_ID = {$Enquiry_ID}";
$query = mysqli_query($connection, $query);
}
if(isset($_GET['No'])){
$enquiry_id = $_GET['No'];
$query = "UPDATE enquiries SET Responded = 'No' WHERE Enquiry_ID = {$Enquiry_ID}";
$query = mysqli_query($connection, $query);
}
if(isset($_GET['delete'])){
$review_id = $_GET['delete'];
$query = "DELETE FROM enquiries WHERE Enquiry_ID = {$Enquiry_ID} ";
$delete_query = mysqli_query($connection, $query);
}
?>
<tr>
<td></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
</form>
You can do it with jquery ajax api it performs an asynchronous HTTP (Ajax) request
http://api.jquery.com/jquery.ajax/
Refer the above link which #Sanya Zahid posted and try to do some thing like this:
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" >
$(function() {
$(".submit").click(function() {
var name = $("#name").val();
var age = $("#age").val();
var dataString = 'name='+ name +'&age='+ age;
if(name=='' || age =='')
{
$('.success').fadeOut(200).hide();
$('.error').fadeOut(200).show();
}
else
{
$.ajax({
type: "POST",
url: "submit.php",
data: dataString,
success: function(){
$('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
}
});
}
return false;
});
});
</script>
<form method="post" name="form">
<input id="name" name="name" type="text" /><br>
<input id="age" name="age" type="text"/>
<div>
<input type="submit" value="Submit" class="submit"/>
<span class="error" style="display:none"> Please Enter Data</span>
<span class="success" style="display:none"> Data Saved!!</span>
</div>
</form>
Here submit.php contains database related stuff(insert/update/delete). I just added name and age fileds here in code. Add fields as per your form.
submit.php :
<?php
$conn = mysqli_connect("localhost","root","","test");
/* Insert form data with out page refresh */
if($_POST)
{
$name=$_POST['name'];
$age = $_POST['age'];
mysqli_query($conn,"Query will come here");
}else{
echo "Please try again!!";
}
/* Insert form data with out page refresh */
?>