首先创建一个Ajax类(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,出现如下提示:
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn