Check If A User Exists In Database Or Not Using JScript Or Ajax

jscript Check if a user exists in database
jscript Check if a user exists in database



I’ve seen this question posted many times in the Messageboard… Typically this is done to determine if a user name already exists, common to many login required sites. Many people query the database and then check the values against the returned values through a loop of some sort.it will show an alert message to user id exist or not. If they don’t find it, they then add the record.



Demo
Download Code

Database

MySQL admin table columns id, username, passcode.
CREATE TABLE admin
(
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(30) UNIQUE,
passcode VARCHAR(30)
);

Config.php

Database configuration file.
<?php
define(‘DB_SERVER’, ‘localhost’);
define(‘DB_USERNAME’, ‘username’);
define(‘DB_PASSWORD’, ‘password’);
define(‘DB_DATABASE’, ‘database’);
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>

login.php

Contains PHP and HTML code.

<?php
include(“config.php”);
$c=$_GET[‘usriddd’];
$sql=”select * from admin where username=’$c'”;
$result=mysqli_query($db,$sql);

$count=mysqli_num_rows($result);

if($count>=1)
{
echo”Not Availble”;
}

else
{
echo”Availble”;
}

?>



Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code