search
HomeBackend DevelopmentPHP TutorialPHP classic project case-(1) Blog management system 4_PHP tutorial

PHP Classic Project Case-(1) Blog Management System 4

This article uses Ajax to verify whether the user name exists without refreshing the page.

7. Registration page implementation

1. Registration page design

Part of register.php code:
<tr>
    <!-- 注册表 --> 
      <td colSpan=3 valign="baseline" style="BACKGROUND-IMAGE: url( images/bg.jpg); VERTICAL-ALIGN: middle; HEIGHT: 450px; TEXT-ALIGN: center"><br>
        
      </td> 
    </tr> 

2. Implementation of the javascript function called after the input box loses focus: fun.js:

function chkUserName(){
	var c = document.getElementById(&#39;txt_regname&#39;);
	var d = c.value;
	var id;
	if(d==""){		
		document.getElementById(&#39;l1&#39;).innerText="请输入用户名";
		document.getElementById(&#39;ll1&#39;).innerText="";
	}else{
		var xmlObj;
		xmlObj = new XMLHttpRequest();	
		xmlObj.open(&#39;POST&#39;,&#39;chk.php?d=&#39;+d,true);
		xmlObj.onreadystatechange = callBackFun;
		xmlObj.send(null);
		function callBackFun() {
			if(xmlObj.readyState == 4&&xmlObj.status ==200){
				if(xmlObj.responseText==&#39;y&#39;){
					document.getElementById(&#39;l1&#39;).innerText="&#215;";
					document.getElementById(&#39;ll1&#39;).innerText="";
				}else{
					document.getElementById(&#39;l1&#39;).innerText="";
					document.getElementById(&#39;ll1&#39;).innerText="√";
				}
			}
		}
	}
}
function chkRealName(){
	var c = document.getElementById(&#39;txt_regrealname&#39;);
	var d = c.value;
	if(d==""){		
		document.getElementById(&#39;l4&#39;).innerText="请输入真实姓名";
		document.getElementById(&#39;ll4&#39;).innerText="";
	}else{
		document.getElementById(&#39;l4&#39;).innerText="";
		document.getElementById(&#39;ll4&#39;).innerText="√";
	}
}
function chkPwd(){
	var p = document.getElementById(&#39;txt_regpwd&#39;).value;
	var c = document.getElementById(&#39;ll1&#39;).innerText;
	if(c=="√"){
		if(p==""){
			document.getElementById(&#39;l2&#39;).innerText="请输入密码";
		}
		else if(p.length<3){
		document.getElementById(&#39;l2&#39;).innerText="&#215;";
		document.getElementById(&#39;ll2&#39;).innerText="";
		}else{
		document.getElementById(&#39;l2&#39;).innerText="";
		document.getElementById(&#39;ll2&#39;).innerText="√";
	    }
	}
}
function chkRePwd(){
	var p = document.getElementById(&#39;txt_regpwd&#39;).value;
	var rp = document.getElementById(&#39;txt_regpwd2&#39;).value;
	var c = document.getElementById(&#39;ll2&#39;).innerText;
	if(c=="√"){
	if(p==rp){
		document.getElementById(&#39;ll3&#39;).innerText="√";
		document.getElementById(&#39;l3&#39;).innerText="";
	}else{
		document.getElementById(&#39;ll3&#39;).innerText="";
		document.getElementById(&#39;l3&#39;).innerText="&#215; 密码不一致";
	}
	}
}
function chkBirth(){
	var c = document.getElementById(&#39;birth&#39;);
	var d = c.value;
	if(d==""){		
		document.getElementById(&#39;l6&#39;).innerText="请输入出生日期";
		document.getElementById(&#39;ll6&#39;).innerText="";
	}else{
		document.getElementById(&#39;l6&#39;).innerText="";
		document.getElementById(&#39;ll6&#39;).innerText="√";

	}
}
function chkEmail(){
	var e = document.getElementById(&#39;txt_regemail&#39;).value;
	if(e==""){		
		document.getElementById(&#39;l5&#39;).innerText="请输入邮箱";
		document.getElementById(&#39;ll5&#39;).innerText="";
	}else{
		document.getElementById(&#39;l5&#39;).innerText="";
		document.getElementById(&#39;ll5&#39;).innerText="√";
	}
}

3. The processing file chk.php used for Ajax verification of username:

'
<?php
    require_once &#39;Conn/SqlHelper.class.php&#39;;
    $chk = $_REQUEST[&#39;d&#39;];
    $sqlHelper = new SqlHelper();
    $sql = "select * from tb_user where regname=&#39;$chk&#39;;";
    $res = $sqlHelper->execute_dql($sql);
    $s = $res->fetch_assoc();
    if(count($s)!=0){
        echo &#39;y&#39;;
    }else{
        echo &#39;n&#39;;
    }

4. After registration, add the user to the database registerdeal.php

<?php
session_start();
include "Conn/SqlHelper.class.php";
$sqlHelper = new SqlHelper();
$UserName=$_POST[&#39;txt_regname&#39;];
$sql="select * from tb_user where regname = &#39;$UserName&#39;";
$res = $sqlHelper->execute_dql($sql);
$result=$res->fetch_assoc();
if (count($result)!=0){
	echo ("<script>alert(&#39;用户名已被注册!&#39;);history.go(-1);</script>");
	exit();
}
$_SESSION[&#39;username&#39;]=$_POST[&#39;txt_regname&#39;];
$regname=$_POST[&#39;txt_regname&#39;];
$regrealname=$_POST[&#39;txt_regrealname&#39;];
$regpwd=$_POST[&#39;txt_regpwd&#39;];
$regbirthday=$_POST[&#39;txt_birthday&#39;];
$regemail=$_POST[&#39;txt_regemail&#39;];
$regcity=$_POST[&#39;txt_province&#39;].$_POST[&#39;txt_city&#39;];
$regico=$_POST[&#39;txt_ico&#39;];
$regsex=$_POST[&#39;txt_regsex&#39;];
$regqq=$_POST[&#39;txt_regqq&#39;];
$reghomepage=$_POST[&#39;txt_reghomepage&#39;];
$regsign=$_POST[&#39;txt_regsign&#39;];
$regintroduce=$_POST[&#39;txt_regintroduce&#39;];
$ip=getenv(REMOTE_ADDR);
$sql = "Insert Into tb_user (regname,regrealname,regpwd,regbirthday,regemail,regcity,regico,regsex,regqq,reghomepage,regsign,regintroduce,ip,fig)".
" Values (&#39;$regname&#39;,&#39;$regrealname&#39;,&#39;$regpwd&#39;,&#39;$regbirthday&#39;,&#39;$regemail&#39;,&#39;$regcity&#39;,&#39;$regico&#39;,&#39;$regsex&#39;,&#39;$regqq&#39;,&#39;$reghomepage&#39;,&#39;$regsign&#39;,&#39;$regintroduce&#39;,&#39;$ip&#39;,0)";
$INS=$sqlHelper->execute_dml($sql);
echo "<script> alert(&#39;用户注册成功!&#39;);</script>";
echo "<script> window.location=&#39;index.php&#39;;</script>";
?>

At this point, user registration has been implemented.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/926458.htmlTechArticlePHP Classic Project Case - (1) Blog Management System 4 This article uses Ajax to verify the user name without refreshing the page exist. 7. Registration page implementation 1. Registration page design register.php part...
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
如何通过PHP编写一个简单的在线借阅管理系统如何通过PHP编写一个简单的在线借阅管理系统Sep 27, 2023 pm 12:49 PM

如何通过PHP编写一个简单的在线借阅管理系统,需要具体代码示例引言:随着数字化时代的到来,图书馆管理方式也发生了巨大的变化。传统的手工记录系统逐渐被在线借阅管理系统所取代。在线借阅管理系统通过自动化处理借阅和归还图书的流程,大大提高了效率。本文将介绍如何使用PHP编写一个简单的在线借阅管理系统,并提供具体的代码示例。一、系统需求分析在开始编写在线借阅管理系统

基于Go语言的智慧物业管理系统实践基于Go语言的智慧物业管理系统实践Jun 20, 2023 am 09:14 AM

随着科技进步和社会发展,智慧物业管理系统成为了现代城市发展不可或缺的一环。在这个过程中,基于Go语言的智慧物业管理系统在其高效、可靠、快速等优势方面备受关注。本文将介绍我们团队使用Go语言的智慧物业管理系统的实践情况。1.需求分析我们的团队主要是为一家房地产公司进行开发这个物业管理系统。其主要任务是将物业公司和居民联系起来,方便物业管理公司的管理,同时也让居

react启动项目报错怎么办react启动项目报错怎么办Dec 27, 2022 am 10:36 AM

react启动项目报错的解决办法:1、进入项目文件夹,启动项目并查看报错信息;2、执行“npm install”或“npm install react-scripts”命令;3、执行“npm install @ant-design/pro-field --save”命令。

ebs系统是什么管理系统ebs系统是什么管理系统Mar 02, 2023 am 11:34 AM

ebs系统是电子制动控制管理系统,是一种电控系统,完全采用电控气制动,提高制动舒适性和安全性。ebs系统的组成:1、EBS系统制动信号传感器;2、EBS系统单通道控制模块;3、EBS系统双通道控制模块;4、EBS系统电控挂车控制阀。

MySQL数据库管理系统的基本原理解析MySQL数据库管理系统的基本原理解析Mar 25, 2024 pm 12:42 PM

MySQL数据库管理系统的基本原理解析MySQL是一种常用的关系型数据库管理系统,它通过结构化查询语言(SQL)来进行数据存储和管理。本文将介绍MySQL数据库管理系统的基本原理,包括数据库的创建、数据表的设计、数据的增删改查等操作,并提供具体的代码示例。一、数据库的创建在MySQL中,首先需要创建一个数据库实例来存储数据。通过以下代码可以创建一个名为"my

如何使用C++编写一个简单的学生宿舍管理系统?如何使用C++编写一个简单的学生宿舍管理系统?Nov 03, 2023 am 08:07 AM

如何使用C++编写一个简单的学生宿舍管理系统?学生宿舍管理系统是一个可以方便管理学生宿舍信息的软件系统。使用C++编写一个简单的学生宿舍管理系统不仅可以锻炼编程技能,还可以提高对学生宿舍管理流程的理解和把握。本文将介绍如何使用C++编写一个简单的学生宿舍管理系统。首先,我们需要定义学生宿舍的基本信息,包括学生姓名、学号、性别、联系方式等。我们可以使用一个结构

如何使用MongoDB开发一个简单的网站后台管理系统如何使用MongoDB开发一个简单的网站后台管理系统Sep 20, 2023 am 08:34 AM

如何使用MongoDB开发一个简单的网站后台管理系统随着互联网的发展,网站的使用和管理变得越来越重要。为了方便网站的管理者对网站内容进行后台管理,开发一个简单而高效的网站后台管理系统是必不可少的。本文将介绍如何使用MongoDB来开发一个简单的网站后台管理系统,并通过具体的代码示例来演示。准备工作首先,我们需要确保已经安装并配置好了MongoDB数据库。具体

学校管理系统的MySQL表结构设计指南学校管理系统的MySQL表结构设计指南Oct 31, 2023 am 10:30 AM

学校管理系统的MySQL表结构设计指南随着社会的不断发展和进步,学校管理系统已经成为各个学校管理教务、学生信息、教师信息等重要数据的核心工具。MySQL作为一种常用的数据库管理系统,被广泛应用于各种软件系统中。设计一个高效、稳定的学校管理系统的MySQL表结构,是确保系统的正常运行和数据安全的关键。下面将为大家提供一个具体的MySQL表结构设计指南,包含必要

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor