I submit my form with JQuery Ajax in php as this :
$("#addForm").submit( function() {
//var valid = jQuery("#addForm").validationEngine('validate');
var valid = true;
if(valid==true) {
// recuperer toutes les informations
var name = $("#name").val();
var type = $('select#type option:selected').val();
var region = $('select#region option:selected').val();
var level = $('select#level option:selected').val();
var nbPers = $("#number_person").val();
var tempsPre = $("#time_pre").val();
var tempsC = $("#time_c").val();
var ings = $("#ing_hide").val();
var etapes = $("#preparation").val();
$.ajax({
type: "POST",
url: "php/add.php",
data: "name="+name+"&type="+type+"®ion="+region+"&level="+level+"&nbPers="+nbPers+"&tempsPre="+tempsPre+"&tempsCui="+tempsC+"&ings="+ings+"&etapes="+etapes,
error : function(request, error) {
alert("Erreur : responseText: "+request.responseText);
},
success: function(msg){ // si l'appel a bien fonctionné
alert('ok');
}
});
return false;
} else {
alert('error');
return false;
}
});
when I debug using firebug, all my variables were correct
but in php files , the var_dump show : undefined for var_dump($_POST['name']); and correct value for var_dump($_POST['ings']);
Note: I dont use isset because I'm only testing that the variable contains value in first
Why I've undefined ?
My HTML form :
<div class="row field_text">
<label class="label_title">Nom :</label>
<input type="text" class="inputtext" name="name" id="name"/>
</div>
<div class="row field_select">
<label class="label_title">Type :</label>
<select class="select_styled" name="type" id="type">
<option value="1">E</option>
<option value="2">P</option>
<option value="3">D</option>
<option value="4">B</option>
</select>
</div>
<div class="row">
<label>Region</label>
<select class="select_styled" name="region" id="region">
<option value="1">Ma</option>
<option value="2">Eu</option>
<option value="3">Af</option>
<option value="4">Mo</option>
<option value="5">As</option>
</select>
</div>
<div class="row field_select">
<label class="label_title">Difficulté :</label>
<select class="select_styled" name="level" id="level">
<option value="1">F</option>
<option value="2">M</option>
<option value="3">D</option>
</select>
</div>
<div class="row field_text">
<label class="label_title">Nombre Personne :</label>
<input type="text" class="inputtext" name="number_person" id="number_person"/>
</div>
<div class="row field_text">
<label class="label_title">Temps pré :</label>
<input type="text" class="inputtext" name="time_pre" id="time_pre"/>
</div>
<div class="row field_text">
<label class="label_title">Temps cui :</label>
<input type="text" class="inputtext" name="time_cook" id="time_cook"/>
</div>
<div class="clear"></div>
<div class="ings_div">
<div class="row field_select">
<label for="ingredient" class="label_title">Ingrédient :</label>
<select id="ingredient" name="basic-combo" size="1" class="select_styled">
<?php include('php\liste-ingredients.php');?>
</select>
</div>
<div class="row field_text">
<label class="label_title">Quantité :</label>
<input id="quantite" type="text" class="inputtext" name="recette_quantite"/>
</div>
<div class="row field_select">
<label class="label_title">Unité :</label>
<select id="unite" class="select_styled" name="unite">
<?php include('php/liste-unites.php'); ?>
</select>
</div>
<div class="row rowSubmit">
<input id="btn_add_ing" type="submit" value="+">
</div>
<div class="rowIng">
<label class="label_title">Liste Ingrédients :</label>
<textarea id="recette_ingredient" class="textareaField required" name="recette_ingredient" cols="5" rows="4"></textarea>
</div>
<div class="rowIngHide">
<label class="label_title">Liste Ingrédients :</label>
<textarea id="recette_ingredient_hide" class="textareaField required" name="recette_ingredient_hide" cols="5" rows="4"></textarea>
</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="preparation_div">
<div class="">
<label class="label_title">Préparation :</label>
<textarea class="textareaField required" name="preparation" id="preparation" cols="8" rows="4"></textarea>
</div>
</div>
<div class="clear"></div>
<div class="row rowSubmit">
<span class="btn btn_search"><input type="submit" value="Ajouter"></span>
</div>
</form>
Related
I am using ajax for submitting data in the database but when I hit submit button in the return response "undefined " value I got, and the problem lies in the controller. I am not sure why I got this error. I am getting this error on fname variable and obv other variables too as they all are similar.
Here is the Controller
public function save(Request $request)
{
$validator = \Validator::make($request->all(), [
'cnic' => 'required|unique:patients',
]);
if ($validator->fails()) {
return response()->json(['success' => false, 'errors' => $validator->errors()->all()]);
}
$temppatientId = IdGenerator::generate(['table' => 'patients', 'length' => 5, 'prefix' => '22']);
$patientid = $temppatientId + 1;
$query = new patient;
$query->patientid = $patientid;
$query->fname =$fname;
$query->lname = $lname;
$query->cnic = $cnic;
$query->contactno = $contactno;
$query->gender = $gender;
$query->age = $age;
$query->dob = $dob;
$query->city = $city;
$query->address = $address;
$query->husbandname = $husbandname;
$query->fathername = $fathername;
$query->bloodgroup = $bloodgroup;
$query->maritalstatus = $maritalstatus;
$query->save();
return response()->json(['success' => true, 'patients' => $query]);
}
Here is the Ajax function
$(document).ready(function() {
$("#save1").on('click', function(e) {
var cnic = $("#cnic").val();
if (cnic == '') {
alert("Kindly Enter CNIC");
return false;
}
var gender = $("#gender").val();
if (gender == '') {
alert("Kindly Enter Gender");
return false;
}
var contactno = $("#contactno").val();
if (contactno == '') {
alert("Kindly Enter Contact No");
return false;
}
var fname = $("#fname").val();
if (fname == '') {
alert("Kindly Enter Name");
return false;
}
else{
$.ajax({
url: "/save",
type: "post",
data: $('#registrationform').serialize(),
dataType: 'json',
success: function(data) {
if (data.success === false) {
alert('CNIC already Exists !');
} else {
$("#patientid").val(data.patient.patientid);
// console.log(data.patient);
}
}
})
}
});
});
this is my blade file
<form class="form" data-parsley-validate id="registrationform" autocomplete="off">
#csrf
<div class="row">
<div class="col-md-4 col-4">
<div class="form-group mandatory">
<label for="first-name-column" class="form-label">First Name</label>
<input type="text" autofocus tabIndex="1" name="fname" id="fname" class="form-control" placeholder="First Name" name="fname" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group">
<label for="last-name-column" class="form-label">Last Name</label>
<input type="text" id="lname" tabIndex="2" class="form-control" placeholder="Last Name" name="lname">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group">
<label for="city-column" class="form-label">Age</label>
<input type="number" id="age" tabIndex="3" class="form-control" placeholder="Age" name="age" >
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group">
<label for="country-floating" class="form-label">DOB</label>
<input type="date" id="dob" tabIndex="4" class="form-control" name="dob" placeholder="Date of Birth">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group choices" mandatory>
<label for="company-column" class="form-label choices">Gender:</label>
<div class="form-group">
<select class="choices form-select" tabIndex="5" id="gender" name="gender">
<option value="">SELECT</option>
<option value="MALE">MALE</option>
<option value="FEMALE">FEMALE</option>
<option value="NEUTER">NEUTER</option>
</select>
</div>
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group mandatory">
<label for="email-id-column" class="form-label">Contact No</label>
<input type="number" id="contactno" tabIndex="6" class="form-control" name="contactno" placeholder="Contact No" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group ">
<label for="email-id-column" class="form-label">Father Name</label>
<input type="text" id="fathername" tabIndex="7" class="form-control" name="fathername" placeholder="Father Name" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group ">
<label for="email-id-column" class="form-label">Husband Name</label>
<input type="text" id="husbandname" tabIndex="8" class="form-control" name="husbandname" placeholder="Husband Name" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group mandatory">
<label for="email-id-column" class="form-label">CNIC</label>
<input type="number" id="cnic" class="form-control" tabIndex="9" name="cnic" placeholder="CNIC" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group ">
<label for="email-id-column" class="form-label">City</label>
<input type="text" id="city" tabIndex="10" class="form-control" name="city" placeholder="City" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group choices">
<label for="company-column" class="form-label choices">Marital Status</label>
<div class="form-group">
<select class="choices form-select" tabIndex="11" id="maritalstatus" name="maritalstatus">
<option value="">SELECT</option>
<option value="NOT SPECIFIED">NOT SPECIFIED</option>
<option value="SINGLE">SINGLE</option>
<option value="MARRIED">MARRIED</option>
<option value="WIDOW">WIDOW</option>
<option value="WIDOWER">WIDOWER</option>
<option value="DIVORCED">DIVORCED</option>
<option value="SEPARATED">SEPARATED</option>
<option value="UNKNOWN">UNKNOWN</option>
</select>
</div>
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group choices">
<label for="company-column" class="form-label choices">Blood Group</label>
<div class="form-group">
<select class="choices form-select" tabIndex="12" id="bloodgroup" name="bloodgroup">
<option value="">SELECT</option>
<option value="NOT SPECIFIED">NOT SPECIFIED</option>
<option value="A POSITIVE">A POSITIVE</option>
<option value="A NEGATIVE">A NEGATIVE</option>
<option value="B POSITIVE">B POSITIVE</option>
<option value="B NEGATIVE">B NEGATIVE</option>
<option value="O POSITIVE">O POSITIVE</option>
<option value="O NEGATIVE">O NEGATIVE</option>
<option value="AB POSITIVE">AB POSITIVE</option>
<option value="AB NEGATIVE">AB NEGATIVE</option>
</select>
</div>
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group mandatory">
<label for="email-id-column" class="form-label">Address</label>
<input type="text" id="address" class="form-control" tabIndex="13" name="address" placeholder="Address" data-parsley-required="true">
</div>
</div>
<div class="col-6 col-lg-3 col-md-6">
<div class="card-body px-2 py-3-4">
<div class="row">
<div class="col-md-4 col-lg-4 col-xl-8 col-xxl-5 d-flex justify-content-start ">
<div class="stats-icon purple mb-2">
<i class="iconly-boldShow"></i>
</div>
</div>
<div class="col-md-8 col-lg-12 col-xl-12 col-xxl-7">
<h6 class="text-muted font-semibold">Patient ID</h6>
<input class="font-extrabold mb-0" style="align-content: center; color:red; " type="number" name="patientid" id="patientid" disabled>
</div>
</div>
</div>
</div>
{{-- <label>Search Patient:</label>
<div class="col-lg-2">
<label>Patient ID:</label>
<input placeholder="Enter Patient ID" type="number" name="patientid"
id="selectpatientid" class="form-control form-control-sm d2">
</div>
<div class="col-lg-2">
<label>Patient CNIC:</label>
<input placeholder="Enter Patient CNIC" type="number" name="cnic"
id="selectpatientcnic" class="form-control form-control-sm d2">
</div>
</div> --}}
<div class="row">
<div class="col-12 d-flex justify-content-end">
<a id="save1" tabIndex="14" class="btn btn-primary me-1 mb-1">Register</a>
{{-- <button type="submit" class="btn btn-light-secondary me-1 mb-1">Register</button> --}}
<button type="reset" class="btn btn-light-secondary me-1 mb-1">Reset</button>
</div>
</div>
</form>
Try opening the F12 tools and heading over to the networking tab, under the networking tab you can double check the CSR under is getting pass along to the app under the 'headers' or 'request' once you've clicked on your jQuery request
You should also be able to see that larval responded with if you click 'response'
It might also be worth checking out the laravel.log under storage provider any more insight to the problem, this normally contains some help hints
I am sending form parameters using serialize() method but the problem is parameters sent are visible in address bar. Even I am using POST method for AJAX request.
Here is the HTML Code for the form I am try to submit.
<form id="addform" method="post">
<div class="form-row">
<div class="form-group col-md-12">
<label for="inputReminder">Reminder Type</label>
<select id="inputReminder" class="form-control" name="inputReminder">
<option value="I">Reminder I</option>
<option value="II">Reminder II</option>
<option value="III">Reminder III</option>
<option value="General">General</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="inputLetterref">Reminder Reference No.</label>
<input type="text" class="form-control" id="inputLetterref" name="inputLetterref" placeholder="Reminder Reference No." required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="inputLetterdate">Reminder Date</label>
<input type="text" readonly="readonly" class="form-control sel-date" id="inputLetterdate" name="inputLetterdate" placeholder="Reminder Date" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<button type="submit" class="btn btn-primary">Add Reminder </button>
</div>
</div>
</form>
jQuery AJAX request:
$("#addform").submit(function(event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: 'submitdetails.php',
data: $(this).serialize()
}).done(function(data) {
$('#result').html(data);
}).error(function(data) {
$('#result').html(data);
});
});
You can try:
$("#addform").submit(function(event){
event.preventDefault();
$.ajax({
type: 'POST',
url : 'submitdetails.php',
data: $(this).serialize(),
done: function(data){
console.log(data)
$('#result').html(data);
},
fail: function(data){
$('#result').html(data);
}
})
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="addform" method="post">
<div class="form-row" id="reminderresult">
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="inputReminder">Reminder Type</label>
<select id="inputReminder" class="form-control" name="inputReminder">
<option value="I">Reminder I</option>
<option value="II">Reminder II</option>
<option value="III">Reminder III</option>
<option value="General">General</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="inputLetterref">Reminder Reference No.</label>
<input type="text" class="form-control" id="inputLetterref" name="inputLetterref" placeholder="Reminder Reference No." required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="inputLetterdate">Reminder Date</label>
<input type="text" readonly="readonly" class="form-control sel-date" id="inputLetterdate" name="inputLetterdate" placeholder="Reminder Date" required>
</div>
</div>
<button type="submit" class="btn btn-primary">Add Reminder </button>
</form>
Is there a way to transfer select tag selected option on clicking a button to go to another page where the previously selected option to already be selected. I am doing it in laravel is there a way to do it.
my index.blade.php:
<section class="all-slide-carousel-caption">
<div class="container">
<form action="{{url('/booking')}}" class="package-reservation">
<select name="packageType" id="Package_Type" class="dynamic" data-dependent="Package_Name">
<option value="" selected disabled>Select Package Type</option>
#foreach($package_list as $list)
<option value="{{ $list->Package_Type}}">{{ $list->Package_Type }}</option>
#endforeach
</select>
<select name="packageName" id="Package_Name" class="dynamic">
<option value="">Select Package</option>
</select>
#csrf
<div class="reservation-button">
<button type="button" class="btn btn-primary font-weight-bold">Booking</button>
</div>
</form>
</div>
</section>
<script>
$(document).ready(function(){
$('.dynamic').change(function(){
if($(this).val() != '')
{
var select = $(this).attr("id");
var value = $(this).val();
var dependent = $(this).data('dependent');
var _token = $('input[name="_token"]').val();
$.ajax({
url:"{{ route('index.fetch') }}",
method:"POST",
data:{select:select, value:value, _token:_token, dependent:dependent},
success:function(result)
{
$('#'+dependent).html(result);
}
})
}
});
$('#Package_Type').change(function(){
$('#Package_Name').val('');
});
});
</script>
My indexController:
class IndexController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$banners = banner::all();
$WhyWithUs = WhyWithUs::all();
$package = Package::all();
$package_list = DB::table('packages')
->groupBy('Package_Type')
->get();
$testimonials = testimonials::all();
return view('pages.index',compact('banners','testimonials','package','WhyWithUs'))->with('package_list', $package_list);
}
function fetch(Request $request)
{
$select = $request->get('select');
$value = $request->get('value');
$dependent = $request->get('dependent');
$data = DB::table('packages')
->where($select, $value)
->groupBy($dependent)
->get();
$output = '<option value="" disabled selected >Select '.str_replace('_',' ',$dependent).' </option>';
foreach($data as $row)
{
$output .= '<option value="'.$row->$dependent.'">'.$row->$dependent.'</option>';
}
echo $output;
}
}
My booking.blade.php where i want it to be selected in when i press booking button in index.blade.php:
<section id="booking-form" class="mt-5 mb-5">
<div class="container">
<h1 class="font-weight-bold text-capitalize">Flight Booking</h1>
<p class="font-weight-bold">Please enter the details below:</p>
<form action="post" class="booking-form">
<div class="personal-details">
<legend> Personal Details </legend>
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputname">Name *</label>
<input type="text" class="form-control" id="inputname" placeholder="Name" required>
</div>
<div class="form-group col-md-6">
<label for="inputnumber" class="font-weight-bold">Phone Number *</label>
<input type="text" class="form-control" id="inputnumber" placeholder="Phone Number" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputEmail">Email</label>
<input type="email" class="form-control" id="inputEmail" placeholder="Email" required>
</div>
<div class="form-group col-md-6">
<label for="country" class="font-weight-bold">Phone Number</label>
<input type="text" class="form-control" id="country" placeholder="Country">
</div>
</div>
</div>
<div class="package-details">
<legend> Package Details </legend>
<div class="package-reservation form-row">
<div class="form-group col-md-6">
<select name="packageType" id="Package_Type" class="dynamic" data-dependent="Package_Name" required>
<option value="" selected disabled>Select Package Type</option>
#foreach($package_list as $list)
<option value="{{ $list->Package_Type}}">{{ $list->Package_Type }}</option>
#endforeach
</select>
</div>
<div class="form-group col-md-6">
<select name="packageName" id="Package_Name" class="dynamic" required>
<option value="">Select Package</option>
</select>
</div>
#csrf
</div>
</div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="gridCheck" required>
<label class="form-check-label font-weight-bold" for="gridCheck">
I accept the Terms and Conditions
</label>
</div>
</div>
<button class="book" type="button" class="btn btn-outline-primary">Submit</button>
</form>
</div>
</section>
You could send a form by clicking the button. Then when the function is called return a view and pass the already selected option.
return view('booking')->with(['selected_package_type' => $request->packageType]);
And then in booking.blade.php
<select name="packageType" id="Package_Type" class="dynamic" data-dependent="Package_Name" required>
<option value="" disabled>Select Package Type</option>
#foreach($package_list as $list)
<option #if($list->Package_Type == $selected_package_type) selected #endif value="{{ $list->Package_Type}}">
{{ $list->Package_Type }}
</option>
#endforeach
</select>
I want to create a submit form to enter MySQL db data and image. I want to make do this using same form through jquery ajax. I tried my best with following code. I couldn't be success. When I enter id I want auto fill email and name field auto. I did it through ajax successfully. I couldn't submit both file and data through ajax.
<?php
print_r($_POST);
print_r($_FILES);
?>
<form class="form-horizontal" action="postvaccode2.php" method="post" id="data" enctype="multipart/form-data">
<fieldset>
<!-- Form Name -->
<legend>Post Vacancy</legend>
<!-- Select Basic -->
<div class="form-group">
<div class="col-md-5">
<select id="cato" name="cato" class="form-control" id="cato">
<option value="IT">IT</option>
<option value="Finance">Finance</option>
</select>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<div class="col-md-6">
<input id="comid" name="comid" type="text" placeholder="comid" class="form-control input-md" required="" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<div class="col-md-6">
<input id="loc" name="loc" type="text" placeholder="city or town" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<div class="col-md-8">
<input id="qul" name="qul" type="text" placeholder="qulification" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<div class="col-md-8">
<input id="indate" name="indate" type="date" placeholder="indate" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<div class="col-md-4">
<input id="expdate" name="expdate" type="date" placeholder="expdate" class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<input id="gpa" name="gpa" type="text" placeholder="gpa" class="form-control input-md">
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<input id="des" name="des" type="text" placeholder="description" class="form-control input-md">
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<input id="title" name="title" type="text" placeholder="title" class="form-control input-md">
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<input id="comname" name="comname" type="text" placeholder="name" class="form-control input-md">
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<input id="email" name="email" type="text" placeholder="email" class="form-control input-md">
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<input id="image" name="image" type="file" class="form-control input-md">
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<input id="vacpost" name="vacpost" type="button" class="form-control input-md">
</div>
</div>
</fieldset>
</form>
<script>
$('#comid').on('input',function(e){
$.ajax({
type: "POST",
url: "postvaccode.php",
data: {id:$('#comid').val()},
success: function (response) {
var partsOfStr = response.split(',');
$('#comname').val(partsOfStr[0]);
$('#email').val(partsOfStr[1]);
}
});
});
</script>
<script>
$("form#data").submit(function(){
var formData = new FormData($(this)[0]);
$.ajax({
url: "postvaccode3.php",
type: 'POST',
data: formData,
async: false,
success: function (data) {
alert(data)
},
cache: false,
contentType: false,
processData: false
});
return false;
});
</script>
postvaccode3.php
<?php
include('dbconnection.php');
if(isset($_POST['comid'])) {
$comid = $_POST['comid'];
$cato = $_POST['cato'];
$loc = $_POST['loc'];
$qul = $_POST['qul'];
$indate = $_POST['indate'];
$expdate = $_POST['expdate'];
$gpa = $_POST['gpa'];
$des = $_POST['des'];
$title = $_POST['title'];
$comname = $_POST['comname'];
$email=$_POST['email'];
$sql="insert into vacancy(companyid,catogary,location,qulification,indate,expectgpa,description,title,expdate,company_name,email,image) values($comid,'$cato','$loc','$qul','$indate','$gpa','$des','$title','$expdate','$comname','$email')";
if(mysqli_query($conn,$sql)){
echo "great";
}
else{
echo "not great";
}
}
?>
I'm getting the nominee_role value from add_employee file.
In nominee_role im getting 7000 as a result, but when I'm trying to get the data value in alert it returns some html contents.
<?php
include('database.php');
include("header.php");
include("left_side_bar.php");
?>
<div class="row">
<!-- left column -->
<div class="col-xs-12">
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">
Add employee
</h3>
<?php
extract($_POST);
//echo $name;
$current_date=date("Y-m-d");
if(isset($_POST['submit']))
{
//echo "hi";
$select = "SELECT * FROM `emp_details` WHERE `branch_name` = '".$branch_code."' AND `emp_role` = '".$emp_role."' ORDER BY id DESC LIMIT 1";
//echo $select;
$exe_select=mysql_query($select);
$fetch=mysql_fetch_array($exe_select);
$rows = mysql_num_rows($exe_select);
$emp_id ='0001';
if($rows == 0)
{
$emp_id ='0001';
$emp_code=$branch_code.$emp_role.$emp_id;
//echo "employee code: ".$emp_code;
}
else
{
$emp_id=$fetch['emp_code'];
echo $emp_id;
//exit();
$emp_id= $emp_id +1;
$emp_code=$emp_id;
//echo "employee code: ".$emp_code;
}
//exit();
$sql="INSERT INTO `emp_details`
(`emp_name`, `emp_code`, `emp_role`, `dob`, `age`, `address`, `contact_number`, `gender`, `pan`, `bank_acc`, `ifsc_code`, `branch_name`,`intro_code`, `nom_name`, `nom_address`, `nom_age`, `nom_gender`, `relationship_status`, `created_date`)
VALUES
('".$name."', '".$emp_code."', '".$emp_role."', '".$dob."', '".$age."', '".$address."', '".$contact_num."', '".$gender."', '".$pan."', '".$acc_num."', '".$ifsccode."', '".$branch_code."', '".$intro_code."', '".$nom_name."', '".$nom_add."', '".$nom_age."', '".$nom_gender."', '".$rel_status."', '".$current_date."' )";
//print_r($sql);
//exit();
$exe_query=mysql_query($sql);
if($exe_query)
{
echo '<h3 class="msyqlsuccess">Employee Details Added Successfully</h3>';
}
else
{
echo '<h3 class="msyqlerror">Employee Details Not Added</h3>'; }
}
?>
</div>
</div>
<!-- form start -->
<form role="form" method="post" class="agentdetails" id="add_agent_details" enctype="multipart/form-data">
<div class="box-body clearfix">
<div class="form-group">
<label>Name</label>
<input type="text" placeholder="Enter Employee Name" id="name" required="required" name="name" class="form-control" />
</div>
<div class="form-group">
<label>DOB</label>
<input type="text" placeholder="Enter DOB" id="date_of_birth" required="required" name="dob" class="form-control" />
</div>
<div class="form-group">
<label>Age</label>
<input type="text" placeholder="Enter Employee Age" id="age" required="required" name="age" class="form-control" />
</div>
<div class="form-group">
<label>Address</label>
<input type="text" placeholder="Enter Employee Address" id="address" required="required" name="address" class="form-control" />
</div>
<div class="form-group">
<label>Contact Number</label>
<input type="text" placeholder="Enter Contact Number" id="contact_num" required="address" name="contact_num" class="form-control" />
</div>
<div class="form-group">
<label>Gender</label>
<select name="gender" id="gender" class="select">
<option value="Female">Female</option>
<option value="Male">Male</option>
</select>
</div>
<div class="form-group">
<label>Employee Role</label>
<select name="emp_role" id="" class="select">
<option value="">---Select User Role---</option>
<option value="1000">Adviser</option>
<option value="2000">Agency Manager</option>
<option value="3000">Sales Manager</option>
<option value="4000">Business Development Manager</option>
<option value="5000">Executive Manager</option>
<option value="6000">Senior Executive Manager</option>
<option value="7000">Director</option>
</select>
</div>
<div class="form-group">
<label>Branch Name</label>
<select name="branch_code" id="" class="select">
<option value="">--Select Branch--</option>
<option value="130">Chennai</option>
<option value="150">Pondicherry</option>
</select>
</div>
<div class="form-group">
<label>PAN Number</label>
<input type="text" placeholder="Enter PAN" id="pan" required="required" name="pan" class="form-control" />
</div>
<div class="form-group">
<label>Bank Account</label>
<input type="text" placeholder="Enter Bankacc" id="acc_num" required="required" name="acc_num" class="form-control" />
</div>
<div class="form-group">
<label>IFSC Code</label>
<input type="text" placeholder="Enter IFSC Code" id="ifsccode" required="required" name="ifsccode" class="form-control" />
</div>
<div class="form-group">
<label>Introducer Code</label>
<input type="text" placeholder="Enter Introducer Code" id="intro_code" required="required" name="intro_code" class="form-control" />
</div>
<div class="form-group">
<label>Nominee Role</label>
<select name="nominee_role" class="select nominee">
<option value="">---Select Nominee Role---</option>
<option value="1000">Adviser</option>
<option value="2000">Agency Manager</option>
<option value="3000">Sales Manager</option>
<option value="4000">Business Development Manager</option>
<option value="5000">Executive Manager</option>
<option value="6000">Senior Executive Manager</option>
<option value="7000">Director</option>
</select>
</div>
<div class="form-group">
<label>Nominee Name</label>
<select name="nom_name" id="" class="select nominee_name">
<option value="">---Select Nominee Role---</option>
<?php
echo $nominee_role = $_POST['nominee_role'];
//echo "hi";
//load nominee name
$get_nominee="SELECT * FROM `emp_details` WHERE `nom_role` = '".$nominee_role."'";
echo $get_nominee;
$exe_nominee=mysql_query($get_nominee);
$is_nominee=mysql_fetch_array($exe_nominee);
$nominee_row=mysql_num_rows($exe_nominee);
if($is_nominee)
{
echo '<option value="'.$is_nominee['emp_code'].'">'.$is_nominee['nom_name'].'</option>';
}
else
{
echo '<option value="">No names are found</option>';
}
?>
</select>
</div>
<div class="form-group">
<label>Nominee Age</label>
<input type="text" placeholder="Enter Nominee Age" id="nom_age" required="required" name="nom_age" class="form-control" />
</div>
<div class="form-group">
<label>Nominee Address</label>
<input type="text" placeholder="Enter Nominee Address" id="nom_add" required="required" name="nom_add" class="form-control" />
</div>
<div class="form-group">
<label>Nominee Gender</label>
<select name="nom_gender" id="" class="select">
<option value="female">Female</option>
<option value="male">Male</option>
</select>
</div>
<div class="form-group">
<label>Relationship Status</label>
<input type="text" placeholder="Enter Relationship Status" id="rel_status" required="required" name="rel_status" class="form-control" />
</div>
<div class="box-footer">
<?php //if($num){ ?>
<!-- <button class="btn btn-primary" id="next" value="Update" type="submit" name="submit" style="margin-top: 6%;">Update</button>
--> <?php //} else { ?>
<button class="btn btn-primary submit" id="add_agent_details" value="Submit" type="submit" name="submit">Submit</button>
<?php //} ?>
</div>
</div>
</form>
</div>
</div>
<?php
include("footer.php");
die;
?>
<script>
$('.nominee').change(function () {
var nominee_role = $('.nominee').val();
alert(nominee_role); // '7000'
//send nominee role
$.ajax({
type: "POST",
url: "add_employee.php",
data: {nomi_role: nominee_role},
success: function (data) {
alert(data);
}
});
return false;
});
</script>
Kindly help me to solve this! I really don't know where I leave a mistake!
Add die; at the end of add_employee.php file;
while you didnt include your add_employee file then lets say you have this in that file.
$your_var = 7000 ;
$other_value = 8000 ;
echo json_encode(array("val"=>$your_var , "val2"=>$other_value ));
then in your ajax you should have this :
$.ajax({
type: "POST",
url: "add_employee.php",
data: {nomi_role: nominee_role},
success: function (data) {
alert(data.val); //will give you 7000.
alert(data.val2); //will give you 8000.
}
});
Hope that helps .