<!DOCTYPE html>
<html>
<head>
	<title>Insert data in MySQL database using Ajax</title>
	
	
	<script src='../js/jquery-3.1.1.min.js' type='text/javascript'></script>
    <script src='../js/jquery-ui.min.js' type='text/javascript'></script>
    <link href="../css/style.css" rel="stylesheet" />
    <link href="../css/style1.css" rel="stylesheet" />
    <link href='../css/jquery-ui.min.css' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="../css/all.css">
    <link href="../css/bootstrap.min.css" rel="stylesheet" />
    <link href="../css/font-awesome.min.css" rel="stylesheet" />
    <link href="../css/styleg.css" rel="stylesheet" />
    <!--script src="../js/jquery.min.js"></script-->
    <script type="text/javascript" src="../js/jquery.placeholder.label.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.5/datepicker.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.5/datepicker.css" />
    <script src="../js/jquery.maskedinput.js" type="text/javascript"></script>
</head>
<body>
<div style="margin: auto;width: 60%;">
	<form id="fupForm" name="form1" method="post">
	    <div class="col-xs-2">
			<label style="font-size:18px;" class="col-sm-2 control-label">Name</label>
			<input type="text" name="name" id="name" class="roundedCategory" tabindex="1" style="font-size:18px; width:100%; height: 35px; margin-top : -10px; font-weight:bold; color: #000066;" value="<?php echo $srno; ?>"  oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
		</div>
		<div class="col-xs-2">
			<label style="font-size:18px;" class="col-sm-2 control-label">Email</label>
			<input type="text" name="email" id="email" class="roundedCategory" tabindex="1" style="font-size:18px; width:100%; height: 35px; margin-top : -10px; font-weight:bold; color: #000066;" value="<?php echo $srno; ?>"  oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
		</div>
		<div class="col-xs-2">
			<label style="font-size:18px;" class="col-sm-2 control-label">Phone</label>
			<input type="text" name="phone" id="phone" class="roundedCategory" tabindex="1" style="font-size:18px; width:100%; height: 35px; margin-top : -10px; font-weight:bold; color: #000066;" value="<?php echo $srno; ?>"  oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
		</div>
		<div class="col-xs-2">
			<label style="font-size:18px;" class="col-sm-2 control-label">City</label>
			<input type="text" name="city" id="city" class="roundedCategory" tabindex="1" style="font-size:18px; width:100%; height: 35px; margin-top : -10px; font-weight:bold; color: #000066;" value="<?php echo $srno; ?>"  oninput="this.value = this.value.toUpperCase()" autocomplete="off" required>
		</div>
		<input type="button" name="save" class="btn btn-primary" style = "width : 200px; height: 35px; margin-top : 20px;" value="Save" id="butsave">
	</form>
	
	<div class="alert alert-success alert-dismissible" id="success" style="display:none; font-size:24px;">
	  <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
	</div>
	<div class="alert alert-danger alert-dismissible" id="error" style="display:none; font-size:24px;">
	  <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
	</div>
	<div class="alert alert-info alert-dismissible" id="info" style="display:none; font-size:24px;">
	  <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
	</div>
</div>

<script>
$(document).ready(function() {
$('#butsave').on('click', function() {
//$("#butsave").attr("disabled", "disabled");
var name = $('#name').val();
var email = $('#email').val();
var phone = $('#phone').val();
var city = $('#city').val();
if(name!="" && email!="" && phone!="" && city!=""){
	$.ajax({
		url: "save.php",
		type: "POST",
		data: {
			name: name,
			email: email,
			phone: phone,
			city: city				
		},
		cache: false,
		success: function(dataResult){
			var dataResult = JSON.parse(dataResult);
			if(dataResult.statusCode==200){
				$("#butsave").removeAttr("disabled");
				$('#fupForm').find('input:text').val('');
				$("#success").show();
				$('#success').show(1000).html("Record Saved Successfully.").delay(1000).fadeOut(1000);
			}
			else if(dataResult.statusCode==201){
			    $('#error').show(1000).html("Record Not Saved !.").delay(1000).fadeOut(1000);
			}
			
		}
	});
	}
	else{
	    $('#info').show(1000).html("Please fill all the fields !.").delay(1000).fadeOut(1000);
		//alert('Please fill all the field !');
	}
});
});
</script>
</body>
</html>