“check_username” Kode Jawaban

check_username

$(document).ready(function(){

   $("#txt_username").keyup(function(){

      var username = $(this).val().trim();

      if(username != ''){

         $.ajax({
            url: 'ajaxfile.php',
            type: 'post',
            data: {username:username},
            success: function(response){

               // Show response
               $("#uname_response").html(response);

            }
         });
      }else{
         $("#uname_response").html("");
      }

   });

});
usman muhammed

check_username

<?php
include 'config.php';

if(isset($_POST['username'])){
   $username = $_POST['username'];

   // Check username
   $sql = "select count(*) as allcount from users where username=$1";
   $result = pg_query_params($con, $sql, array($username));
   $row = pg_fetch_assoc($result);
   $count = $row['allcount'];

   $response = "<span style='color: green;'>Available</span>";
   if($count > 0){
      $response = "<span style='color: red;'>Not Available</span>";
   }

   echo $response;
   exit;
}
usman muhammed

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya