search
HomeBackend DevelopmentPHP Tutorial求一段php注册代码

公司内部网络注册代码
菜鸟请大哥大姐们帮忙
现有表
user
id    姓名  身份证号                 用户名   密码
 1     张三  659001198808091210
 2    李四  659001195101092345

现在需要公司员工在注册页面输入真实姓名和身份证后四位
 姓名:                
 身份证后四位:          
 用户名:
 密码:
 重复密码:
判断姓名和身份证后四位输入正确,以及用户名是否已有,就可以注册,
求输入页面和insert页面
求详细,菜鸟,求助


回复讨论(解决方案)

新建一个html页面 一个php页面
html页面写表单,php页面连接数据库,写php程序接受页面传递过来的值
然后insert到数据库就行了!

如果有什么特殊输入,可以js控制下
验证表单!

检测用户名是否已有,可以用jquery中的$.post()方法连接数据库查看是否已存在,若存在给出提示,这样可以实现无刷新验证,身份证的话JS验证吧,信息都正确后就提交到php页面进行数据库操作,注册新用户

mark 一下,下班后回去给你详细代码

后台:
$con=mysql_connect("   ","   ", "   ");     //简历链接并赋值给变量
if($con)
{
   mysql_select_db("    ",$con);      //选择操作库
   $sql="CREATE TABLE user_data
{
   id  int(5) not null auto_increment primary key,
   name  char(10) not null default ' ',
   card   char(18) not null  default '',
   username char(10)  not null default '',
   password  char(12) not null default ''
)";
$do=mysql_query($sql,$con);    //执行建表SQL语句
if($do)                        //如果成功执行
{
   echo  "成功在        数据库中创建用户表!";      //输出内容
}
else echo "建表时出现错误!";
}
else                                //如果返回False
{
   echo "链接到服务器时出现错误!";
}
?>

公司内部网络注册代码
菜鸟请大哥大姐们帮忙
现有表
user
id    姓名  身份证号                 用户名   密码
 1     张三  659001198808091210
 2    李四  659001195101092345

现在需要公司员工在注册页面输入真实姓名和身份证后四位
 姓名:                ……

不好意思现在才给你弄出来,废话不说,直接上代码:

CREATE TABLE `user` (  `id` int(10) NOT NULL AUTO_INCREMENT,  `name` varchar(32) DEFAULT NULL,  `uid` varchar(32) CHARACTER SET latin1 DEFAULT NULL,  `uname` varchar(64) CHARACTER SET latin1 DEFAULT NULL,  `password` varchar(64) CHARACTER SET latin1 DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

conn.php

<?php$conn=mysql_connect('localhost','root','');mysql_select_db('test');mysql_query("SET NAMES utf8");


reg.php
<?phpinclude 'conn.php';?><html><header><script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script></header><body><script type="text/javascript">$(document).ready(function(){	$('#reg').click(function(){		p1=$.trim($('#p1').val());		p2=$.trim($('#p2').val());		uid=$.trim($('#uid').val());		name=$.trim($('#name').val());		uname=$.trim($('#uname').val());		if(uid.length<4||uid.length<4){			alert('必须输入后4位身份证号');			$('#uid').focus();			return false;		}		if(p1!=p2){			alert('两次密码不一样');			$('#p2').focus();			return false;		}		$.post("check.php",{password:p1,name:name,uid:uid,uname:uname},function(result){						if(result==-1){				alert('姓名或身份证后四位不正确');				$('#name').focus();				return false;			}else if(result==-2){				alert( '账号已经注册');				$('#name').focus();				return false;			}else if(result==1){				alert('恭喜你注册成功!');				$('#tips').html('姓名:'+name+'用户名:'+uname+'密码'+p1);			}		});	});});</script><table align="center"><tr><td>姓名:</td><td><input type="text" name="name" id='name' maxlength='12'></td></tr><tr><td>身份证后四位:</td><td><input type="text" name="uid" id='uid' maxlength='4'></td></tr><tr><td>用户名:</td><td><input type="text" name="uid" id='uname' maxlength='12'></td></tr><tr><td>密码:</td><td><input type="password" name="password1" id="p1" maxlength='12'></td></tr><tr><td>重复密码:</td><td><input type="password" name="password2" id='p2' maxlength='12'></td></tr><tr align="center"><td colspan="2"><button id="reg">注册</button> </td></tr><tr id='tips'></tr></table></body></html>



check.php

<?phpinclude 'conn.php';$puid=$_POST['uid'];$name=$_POST['name'];$password=$_POST['password'];$uname=$_POST['uname'];$sql="select * from user where name='$name' and uid like '%$puid'";if($result=mysql_query($sql)){	while ($row = mysql_fetch_array($result)) {	        $uid=$row['id'];	        $uname2=$row['uname'];	        $password2=$row['password'];	}	if(strlen($name2)>0||strlen($password2)>0){		echo -2;exit;	}	if(is_numeric($uid)){		$sql2="update user set uname=$uname,password=$password where id=$uid ";		if(mysql_query($sql2)){			echo 1;		}	}else{		echo -1;exit;	}}else{	echo -1;exit;}?>

好多可以学习的地方,哈哈

谢谢6789楼,我去测试下,谢谢

测试我输入什么也没提示输入错误,包括javascript的判断,看了半天也不知道哦错在哪里!

请确认该js: http://code.jquery.com/jquery-1.4.1.min.js可以访问

你自己去下载一个jquery然后把它引入进去就好了

是的,我引入了jquery,但是确实无法运行,不过我把这个代码复制到某些网站测试代码的地方时可以运行的,

是的,我引入了jquery,但是确实无法运行,不过我把这个代码复制到某些网站测试代码的地方时可以运行的, reg.php中的
<script> <br /> 下面加入:var p1,p2,uid,name,uname;//js申明变量 <br /> 就好了。我粗心了。 </script>

学习 学习

我把代码完整的发一遍吧:

CREATE TABLE `user` (  `id` int(10) NOT NULL AUTO_INCREMENT,  `name` varchar(32) DEFAULT NULL,  `uid` varchar(32) CHARACTER SET latin1 DEFAULT NULL,  `uname` varchar(64) CHARACTER SET latin1 DEFAULT NULL,  `password` varchar(64) CHARACTER SET latin1 DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;


conn.php
<?php$conn=mysql_connect('localhost','root','');mysql_select_db('test');mysql_query("SET NAMES utf8");


reg.php

<?phpinclude 'conn.php';?><html><header><script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script></header><body><script type="text/javascript">var p1,p2,uid,name,uname;$(document).ready(function(){	$('#reg').click(function(){		p1=$.trim($('#p1').val());		p2=$.trim($('#p2').val());		uid=$.trim($('#uid').val());		name=$.trim($('#name').val());		uname=$.trim($('#uname').val());		if(uid.length<4||uid.length<4){			alert('必须输入后4位身份证号');			$('#uid').focus();			return false;		}		if(p1!=p2){			alert('两次密码不一样');			$('#p2').focus();			return false;		}		$.post("check.php",{password:p1,name:name,uid:uid,uname:uname},function(result){						if(result==-1){				alert('姓名或身份证后四位不正确');				$('#name').focus();				return false;			}else if(result==-2){				alert( '账号已经注册');				$('#name').focus();				return false;			}else if(result==1){				alert('恭喜你注册成功!');				$('#tips').html('姓名:'+name+'用户名:'+uname+'密码'+p1);			}		});	});});</script><table align="center"><tr><td>姓名:</td><td><input type="text" name="name" id='name' maxlength='12'></td></tr><tr><td>身份证后四位:</td><td><input type="text" name="uid" id='uid' maxlength='4'></td></tr><tr><td>用户名:</td><td><input type="text" name="uid" id='uname' maxlength='12'></td></tr><tr><td>密码:</td><td><input type="password" name="password1" id="p1" maxlength='12'></td></tr><tr><td>重复密码:</td><td><input type="password" name="password2" id='p2' maxlength='12'></td></tr><tr align="center"><td colspan="2"><button id="reg">注册</button> </td></tr><tr id='tips'></tr></table></body></html>


check.php
<?phpinclude 'conn.php';$puid=$_POST['uid'];$name=$_POST['name'];$password=$_POST['password'];$uname=$_POST['uname'];$sql="select * from user where name='$name' and uid like '%$puid'";if($result=mysql_query($sql)){	while ($row = mysql_fetch_array($result)) {	        $uid=$row['id'];	        $uname2=$row['uname'];	        $password2=$row['password'];	}	if(strlen($name2)>0||strlen($password2)>0){		echo -2;exit;	}	if(is_numeric($uid)){		$sql2="update user set uname=$uname,password=$password where id=$uid ";		if(mysql_query($sql2)){			echo 1;		}	}else{		echo -1;exit;	}}else{	echo -1;exit;}?>

学习了,看来jq是不错的

花了大时间~~~分都给他吧

check。php页面会有注入风险

为什么我运行的不能判断身份证和姓名是否正确,点击注册没反应

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 Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

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

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

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

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!