Dear Team,
Greetings.
I want to validate the one field with my mysql database. I am having one filed with hotel_name and i want to check that the entered hotel name is already exists in database or not. I am using Bootstrap, JQuery and PHP ad below is my code
JQuery Code:-
------------------------------
$('#form_add_hotel').bootstrapValidator({
message: 'This value is not valid',
live: 'enabled',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
hotel_name: {
verbose: false,
validators: {
stringLength: {
min: 3,
max: 20,
message: 'The hotel name must be more than 3 and less than 20 characters long'
},
notEmpty: {
message: 'The hotel name is required and can\'t be empty'
},
remote: {
type: 'POST',
url: 'php/Validation-hotel.php',
message: 'The hotel name already exists',
data:{
type: 'hotel_name'
}
// delay: 1000
}
}
},
PHP Code:-
---------------------------
require_once('connection.php');
//switch($_POST['type']){
//case 'hotel_name':
$hotel_name = $_POST['type'];
$query
= "SELECT hotel_name from tbl_hotel_general_info WHERE hotel_name = $hotel_name";
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) > 0){
echo true; // Hotel Name already exists
}else{
echo false; // Hotel Name can be added
}
//
}
When i deleted the remote functionality my submit works fine after adding all fields value; means it goes to submit handler and when I add remote functionality it does not go to submit handler and it foucs on hotel_name field if i entered the existing hotel name or different name...
I dont knw that where is the issue