Asked  8 Months ago    Answers:  5   Viewed   33 times

I want to check email availability but it's not working. and also I am new to javascript and ajax please help me.

his is my code email input with span to show output(for now there is no output)

<input class="input--style-4" id="email" type="email" name="email" required>
<span id="user-availability-status"></span>


  $(document).ready(function() {
    $('#email').blur(function() {
      var email = $(this).val();

        url: 'includesemailAvailability.php',
        method: "POST",
        data: {
          email_val: email
        success: function(data) {
          if (data != 0) {
            $('#user-availability-status').html('<span>Username blah not available</span>');
            $('#register').attr("disabled", true);
          } else {
            $('#user-availability-status').html('<span>Username blah Available</span>');
            $('#register').attr("disabled", false);

PHP file


if (isset($_POST["email_val"])) {
    $email = mysqli_real_escape_string($conn, $_POST["email_val"]);
    $query = "SELECT * FROM customer WHERE email = '" . $email . "'";
    $result = mysqli_query($conn, $query);
    echo mysqli_num_rows($result);



You should check link I refered in comment its your complete answer.

here is a Simple example with your code.

    // Set alerts as array 
$error     = "";

    // I should just trrim and let you check if email is empty .lol 
if (empty($_POST["email_val"])) {
    $error .= "<p class='error'>Fill email value.</p>";

    //Check if this is a real email 
} elseif(!filter_var($_POST["email_val"],FILTER_VALIDATE_EMAIL)){
    $error .= "<p class='error'>Wrong email type.</p>";
    $email = mysqli_real_escape_string($conn, $_POST["email_val"]);

    //You should use prepare statement $email, Shame on you .lol    
    $query = "SELECT * FROM customer WHERE email = '{$email}'");
    $result = mysqli_query($conn, $query);
    echo mysqli_num_rows($result);
    $error .= "ok";
$data = array(
 'error'  => $error

This Jquery :

    var formValues = $(this).serialize();
                if(data.error === 'ok'){
                } else {

And Html :

<form id="myform">
  <input class="input--style-4" id="email" type="email" name="email_val">
  <span id="result"></span>
  <button type="button" class="btn btn-primary">Send</button>
Wednesday, March 31, 2021
answered 8 Months ago

"but it doesn't seem to work on my free 000webhost account"

A: They do not offer SMTP for free hosting. Use PHP's mail() function instead.

Notice the red x next to SMTP Server on their site => ?

enter image description here

Either use mail() or pay for it in order to use SMTP.

You can do it on their website, or upgrade from within the control panel.

Edit (Sept. 16, 2016): This answer was posted before they revamped their website. The URL where you can see the available options for free/paid services, can be see here

This also goes for remote connections to a database.

This answer was edited in regards to a question I saw today which was related to my edit.

Wednesday, March 31, 2021
answered 8 Months ago

Post your javascript code.

A blind guess is : you are trying to setup your ajaxForm before it is actually present in the page.

If you want to run ajaxForm on '#brands_form_update', you have to request for it, insert it in the document, then call ajaxForm. This should give something like :

// $.get(...) sends the request
// $(..).append inserts the form inside the document
// $('#brands_form_update').ajaxForm() sets up the form
$.get('myDynamicForm.php', {}, function(html){
Wednesday, March 31, 2021
answered 8 Months ago

Beware of using Gmail from different devices. google doesn't allow and block immediately a location from where an account is used where it isn't supposed to use (in the eyes of google ofcourse).

Wednesday, March 31, 2021
answered 8 Months ago

The first script it's not send through ajax:

 // run long running (later Download) PHP script
  console.log("Calling: PHP/fileDownload.php");
  window.location.href = 'PHP/fileDownload.php';

You simply redirect the user to another page, and because you have download headers in php, the file is downloaded in the same page.

You can easily achieve your scope through an iframe. You set the source of that iframe : 'PHP/fileDownload.php' and then simply call your ajax download checker.

Short example:

<iframe src="PHP/fileDownload.php">

        window.setTimeout(function(){startDownloadMonitoring()}, 1000);
        window.setTimeout(function(){startDownloadMonitoring()}, 3000);
        window.setTimeout(function(){startDownloadMonitoring()}, 5000);
        window.setTimeout(function(){startDownloadMonitoring()}, 7000);
        window.setTimeout(function(){startDownloadMonitoring()}, 9000);
        // .... blah blah
Saturday, May 29, 2021
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :