PHP经典项目案例-(一)博客管理系统4
PHP经典项目案例-(一)博客管理系统4
本篇使用Ajax实现页面无刷新验证用户名是否存在。
七、注册页面实现
1、注册页面设计
register.php部分代码:<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、输入框失去焦点后调用的javascript函数实现:fun.js:
function chkUserName(){ var c = document.getElementById('txt_regname'); var d = c.value; var id; if(d==""){ document.getElementById('l1').innerText="请输入用户名"; document.getElementById('ll1').innerText=""; }else{ var xmlObj; xmlObj = new XMLHttpRequest(); xmlObj.open('POST','chk.php?d='+d,true); xmlObj.onreadystatechange = callBackFun; xmlObj.send(null); function callBackFun() { if(xmlObj.readyState == 4&&xmlObj.status ==200){ if(xmlObj.responseText=='y'){ document.getElementById('l1').innerText="×"; document.getElementById('ll1').innerText=""; }else{ document.getElementById('l1').innerText=""; document.getElementById('ll1').innerText="√"; } } } } } function chkRealName(){ var c = document.getElementById('txt_regrealname'); var d = c.value; if(d==""){ document.getElementById('l4').innerText="请输入真实姓名"; document.getElementById('ll4').innerText=""; }else{ document.getElementById('l4').innerText=""; document.getElementById('ll4').innerText="√"; } } function chkPwd(){ var p = document.getElementById('txt_regpwd').value; var c = document.getElementById('ll1').innerText; if(c=="√"){ if(p==""){ document.getElementById('l2').innerText="请输入密码"; } else if(p.length<3){ document.getElementById('l2').innerText="×"; document.getElementById('ll2').innerText=""; }else{ document.getElementById('l2').innerText=""; document.getElementById('ll2').innerText="√"; } } } function chkRePwd(){ var p = document.getElementById('txt_regpwd').value; var rp = document.getElementById('txt_regpwd2').value; var c = document.getElementById('ll2').innerText; if(c=="√"){ if(p==rp){ document.getElementById('ll3').innerText="√"; document.getElementById('l3').innerText=""; }else{ document.getElementById('ll3').innerText=""; document.getElementById('l3').innerText="× 密码不一致"; } } } function chkBirth(){ var c = document.getElementById('birth'); var d = c.value; if(d==""){ document.getElementById('l6').innerText="请输入出生日期"; document.getElementById('ll6').innerText=""; }else{ document.getElementById('l6').innerText=""; document.getElementById('ll6').innerText="√"; } } function chkEmail(){ var e = document.getElementById('txt_regemail').value; if(e==""){ document.getElementById('l5').innerText="请输入邮箱"; document.getElementById('ll5').innerText=""; }else{ document.getElementById('l5').innerText=""; document.getElementById('ll5').innerText="√"; } }
3、Ajax验证用户名使用的处理文件chk.php:
'<?php require_once 'Conn/SqlHelper.class.php'; $chk = $_REQUEST['d']; $sqlHelper = new SqlHelper(); $sql = "select * from tb_user where regname='$chk';"; $res = $sqlHelper->execute_dql($sql); $s = $res->fetch_assoc(); if(count($s)!=0){ echo 'y'; }else{ echo 'n'; }
4、注册后将用户添加到数据库registerdeal.php
<?php session_start(); include "Conn/SqlHelper.class.php"; $sqlHelper = new SqlHelper(); $UserName=$_POST['txt_regname']; $sql="select * from tb_user where regname = '$UserName'"; $res = $sqlHelper->execute_dql($sql); $result=$res->fetch_assoc(); if (count($result)!=0){ echo ("<script>alert('用户名已被注册!');history.go(-1);</script>"); exit(); } $_SESSION['username']=$_POST['txt_regname']; $regname=$_POST['txt_regname']; $regrealname=$_POST['txt_regrealname']; $regpwd=$_POST['txt_regpwd']; $regbirthday=$_POST['txt_birthday']; $regemail=$_POST['txt_regemail']; $regcity=$_POST['txt_province'].$_POST['txt_city']; $regico=$_POST['txt_ico']; $regsex=$_POST['txt_regsex']; $regqq=$_POST['txt_regqq']; $reghomepage=$_POST['txt_reghomepage']; $regsign=$_POST['txt_regsign']; $regintroduce=$_POST['txt_regintroduce']; $ip=getenv(REMOTE_ADDR); $sql = "Insert Into tb_user (regname,regrealname,regpwd,regbirthday,regemail,regcity,regico,regsex,regqq,reghomepage,regsign,regintroduce,ip,fig)". " Values ('$regname','$regrealname','$regpwd','$regbirthday','$regemail','$regcity','$regico','$regsex','$regqq','$reghomepage','$regsign','$regintroduce','$ip',0)"; $INS=$sqlHelper->execute_dml($sql); echo "<script> alert('用户注册成功!');</script>"; echo "<script> window.location='index.php';</script>"; ?>
至此,用户注册已经实现。

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Fermat's last theorem, about to be conquered by AI? And the most meaningful part of the whole thing is that Fermat’s Last Theorem, which AI is about to solve, is precisely to prove that AI is useless. Once upon a time, mathematics belonged to the realm of pure human intelligence; now, this territory is being deciphered and trampled by advanced algorithms. Image Fermat's Last Theorem is a "notorious" puzzle that has puzzled mathematicians for centuries. It was proven in 1993, and now mathematicians have a big plan: to recreate the proof using computers. They hope that any logical errors in this version of the proof can be checked by a computer. Project address: https://github.com/riccardobrasca/flt

Share the simple and easy-to-understand PyCharm project packaging method. With the popularity of Python, more and more developers use PyCharm as the main tool for Python development. PyCharm is a powerful integrated development environment that provides many convenient functions to help us improve development efficiency. One of the important functions is project packaging. This article will introduce how to package projects in PyCharm in a simple and easy-to-understand way, and provide specific code examples. Why package projects? Developed in Python

PyCharm is a powerful Python integrated development environment that provides a wealth of development tools and environment configurations, allowing developers to write and debug code more efficiently. In the process of using PyCharm for Python project development, sometimes we need to package the project into an executable EXE file to run on a computer that does not have a Python environment installed. This article will introduce how to use PyCharm to convert a project into an executable EXE file, and give specific code examples. head

Title: Learn more about PyCharm: An efficient way to delete projects. In recent years, Python, as a powerful and flexible programming language, has been favored by more and more developers. In the development of Python projects, it is crucial to choose an efficient integrated development environment. As a powerful integrated development environment, PyCharm provides Python developers with many convenient functions and tools, including deleting project directories quickly and efficiently. The following will focus on how to use delete in PyCharm

How to Make a GroceryList on iPhone in iOS17 Creating a GroceryList in the Reminders app is very simple. You just add a list and populate it with your items. The app automatically sorts your items into categories, and you can even work with your partner or flat partner to make a list of what you need to buy from the store. Here are the full steps to do this: Step 1: Turn on iCloud Reminders As strange as it sounds, Apple says you need to enable reminders from iCloud to create a GroceryList on iOS17. Here are the steps for it: Go to the Settings app on your iPhone and tap [your name]. Next, select i

With technological advancement and social development, smart property management systems have become an indispensable part of modern urban development. In this process, the smart property management system based on Go language has attracted much attention due to its advantages such as efficiency, reliability, and speed. This article will introduce the practice of our team’s smart property management system using Go language. 1. Requirements analysis Our team mainly develops this property management system for a real estate company. Its main task is to connect property management companies and residents to facilitate the management of property management companies, and also to allow residents to

How to write a simple online lending management system through PHP requires specific code examples. Introduction: With the advent of the digital age, library management methods have also undergone tremendous changes. Traditional manual recording systems are gradually being replaced by online borrowing management systems. Online borrowing management systems greatly improve efficiency by automating the process of borrowing and returning books. This article will introduce how to use PHP to write a simple online lending management system and provide specific code examples. 1. System requirements analysis before starting to write the online borrowing management system

IDEA (IntelliJIDEA) is a powerful integrated development environment that can help developers develop various Java applications quickly and efficiently. In Java project development, using Maven as a project management tool can help us better manage dependent libraries, build projects, etc. This article will detail the basic steps on how to create a Maven project in IDEA, while providing specific code examples. Step 1: Open IDEA and create a new project Open IntelliJIDEA
