Simple Ajax Example Check for Checking Duplicates PHP JavaScript MySql

I thought it was time that I made a simple post on using AJAX. This is a very easy script for you to develop from. The main thing that you want to keep in mind is that you have to put the following script into a file called test.php.

Further Instructions for Mysql

You will see that this script is calling for a config file for the connection to the database. It is looking for a user table and a user row to call from. If you want to know how to create tables rows and databases see this post. CREATE A NEW TABLE IN A MYSQLI DATABASE.

if(isset($_POST["unamecheck"]) && $_POST["unamecheck"] != ""){
include_once 'config.php';
$username = $_POST['unamecheck'];
$sql_uname_check = $con->query("SELECT user FROM user WHERE user='$username' LIMIT 1") ;

$uname_check = $sql_uname_check->num_rows;

if ($uname_check < 1) {
echo '<strong>' . $username . '</strong> is OK';
} else {
echo '<strong>' . $username . '</strong> is taken';
function checkname(){
var status = document.getElementById("unamestatus");
var u = document.getElementById("uname").value;
if(u != ""){
status.innerHTML = 'checking...';
var hr = new XMLHttpRequest();"POST", "test.php", true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
status.innerHTML = hr.responseText;
var v = "unamecheck="+u;
</script><input id="uname" maxlength="250" name="uname" type="text" /> <span id="unamestatus"></span>

Simple Ajax Example Check for Checking Duplicates PHP JavaScript MySql was last modified: July 8th, 2022 by Maximus Mccullough
PHP Web Development

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.