<?php
session_start(); // Start or resume the session
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
require_once '../db.php';
date_default_timezone_set("Asia/Calcutta");
if(isset($_POST['email'])) {
$email = $conn->real_escape_string($_POST['email']);
$sql = "SELECT date FROM jagran WHERE email = '$email'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
echo $row['date'];
} else {
echo "";
}
}
here is the php code for connection and a query to fetch data from database
below is the html button code & java script i am using.
<script>
$(document).ready(function(){
$('#email').on('blur', function(){
var email = $(this).val();
if(email) {
$.ajax({
url: 'check_email.php',
method: 'POST',
data: { email: email },
success: function(response){
if(response) {
$('#date-display').html('<div class="alert alert-warning">Caution: This email has been registered on ' + response + '.</div>');
} else {
$('#date-display').html('<div class="alert alert-danger">Email not found.</div>');
}
},
error: function(){
$('#date-display').html('<div class="alert alert-danger">Error checking email.</div>');
}
});
}
});
});
</script>
<div class="col-md-6 mb-1 mb-md-2">
<label class="form-label required">Email </label>
<input type="email" class="form-control" id="email" name="email" required>
<div id="email-message" class="mt-2"></div>
</div>
I have a form which also have a email input field. I want to display date from the database table when user enters its email it it will be checked if it exists in the database table the date related to the email will get displayed. this is a booking form for a room so that is the reason why i need it.