使用php+Ajax实现唯一校验实现代码[简单应用],前台用ajax后台用php,需要的朋友可以参考下。
首先创建一个Ajax类()
然后新建一个文件form.html
--------------------------form.html----------------------------
代码如下:
最后新建一个php文件form.php
--------------------------form.html----------------------------
代码如下:
header("Content-type:text/html;charset=gb2312"); //设置字符集
$mysqli = new mysqli("localhost","root","123","demo"); //打开demo数据库
$result = $mysqli->query("select * from zhanghao where name='{$_POST["username"]}'");
if($result->num_rows > 0){ //判断是否查询出数据
echo "用户{$_POST["username"]}已经存在!";
}else{
echo "用户{$_POST["username"]}可以注册";
}
?>
在浏览器中打开form.html出现下图:
注意:需要提前在MySQL数据库中建立一个表“zhanghao”
如果输入已存在的name,则出现如下提示:
如果输入未存在的name,出现如下提示:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor
