PHP 예제-등록 및 로그인

WBOY
풀어 주다: 2016-07-29 09:15:03
원래의
1370명이 탐색했습니다.

------------Re.php------- ---- -------------

<html>
<head>
	<meta http-equiv="Content-Type" c/html; charset=utf-8" />
	<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
	<?php 
		$c //连接并选择数据库服务器 
		mysql_query("set names utf8");
		mysql_select_db("cookie",$connection); 		
	?>
	<script>
	function sel(obj){

	  $.get("select.php",{province:obj.options[obj.selectedIndex].value},function(json){ 
			var city = $("#city"); 
			//$("option",city).remove(); //清空原有的选项 
			$.each(json,function(index,array){ 
				//alert(array.cityid);
				var option = "<option value=&#39;"+array.cityid+"&#39;>"+array.city+"</option>"; 
				city.append(option); 
			}); 
		},'json'); 
	}

	</script>
	<title>Register</title>
</head>
<body>
	
	<h1>用户注册</h1>
	<form method="POST" action="register.php">
	输入工号:<input type="text" name="userno" maxlength="10" size="10"></br></br>
	输入密码:<input type="password" name="password1" maxlength="20" size="20"></br></br>
	确认密码:<input type="password" name="password2" maxlength="20" size="20"></br></br>
	真实姓名:<input type="text" name="username" maxlength="30" size="30"></br></br>
	性    别:<input type="radio" checked="checked" name="gender" value="1">男
		  <input type="radio" name="gender" value="2">女</br></br>
    籍贯:<select name="province" id="province" 
			  <option value ="0">---请选择省份---</option>
	<?
		$query="select * from province"; 
		$result=mysql_query($query,$connection); 
		while($row=mysql_fetch_array($result)) 
		{ 
	?>
			  <option value ="<? echo $row[provinceid]; ?>"><? echo $row[province] ?></option>
		  
	<?
		} 
	?> </select>
		  <select name="city" id="city">
		  <option value ="0">---请选择城市---</option>
		  </select> </br></br>
	所在部门:<select name="department">
			  <option value ="0">---请选择部门---</option>
	<?
		$query="select * from department"; 
		$result=mysql_query($query,$connection); 
		while($row=mysql_fetch_array($result)) 
		{ 
	?>
			  <option value ="<? echo $row[departmentid]?>"><? echo $row[department]?></option>
	<?
		} 
	?>
		  </select></br></br>
	职位:<select name="position">
			  <option value ="0">---请选择职位---</option>
	<?
		$query="select * from positions"; 
		$result=mysql_query($query,$connection); 
		while($row=mysql_fetch_array($result)) 
		{ 
	?>
			  <option value ="<? echo $row[positionid]?>"><? echo $row[positions]?></option>
	<?
		} 
	?>
		  </select></br></br>
	备注:<input type="text" name="remark" maxlength="30" size="30"></br></br>
	<input type="submit" value="提交">
	</form>
</body>
</html>
로그인 후 복사

------------ --- ----------register.php--------- ------
<html>
<head>
	<meta http-equiv="Content-Type" c/html; charset=utf-8" />
	<title>Register</title>
</head>
	<body>
		<?php
		
			$userno = $_POST[&#39;userno&#39;];
			$password1 = $_POST[&#39;password1&#39;];
			$password2 = $_POST[&#39;password2&#39;];
			$username = $_POST[&#39;username&#39;];
			$gender = $_POST[&#39;gender&#39;];
			$province = $_POST[&#39;province&#39;];
			$city = $_POST[&#39;city&#39;];
			$department = $_POST[&#39;department&#39;];
			$position = $_POST[&#39;position&#39;];
			$remark = $_POST[&#39;remark&#39;];
			
			
			
			if(!$password1 || !$username)
			{
				echo "用户名或密码不能为空,请重新输入!";
				exit;
			}
			if($password1 != $password2)
			{
				echo "两次密码不一致,请重新输入!";
				exit;
			}
			@ $db = new mysqli(&#39;localhost&#39;,&#39;root&#39;,&#39;cookie&#39;,&#39;cookie&#39;);
			
			if(mysqli_connect_errno())
			{
				echo "数据库链接失败,请重试!";
				exit;
			}
			
			
			
			$query = "insert into userinfo values(null,$userno,&#39;$password1&#39;,&#39;$username&#39;,$gender,$province,$city,$department, $position,&#39;remark&#39;)";
			$result = $db->query($query);
			if($result)
			{
				echo "注册成功!<br />";
			}
			else
			{
				echo "注册失败!";
			}
			$db->close();
		?>
		<a href="login.html">点击登录</a>
	</body>
</html>
로그인 후 복사

---------------select.php--------------- ------
<?
		$c //连接并选择数据库服务器 
		mysql_query("set names utf8");
		mysql_select_db("cookie",$connection); 	
		
		$proid = $_GET["province"]; 
			if(isset($proid)){ 
				$q=mysql_query("select * from city where provinceid = $proid"); 
				while($row=mysql_fetch_array($q)){ 
					$select[] = array("cityid"=>$row[cityid],"city"=>$row[city]); 
				} 
				//var_dump($select);
			 echo json_encode($select); 
			}
?>
로그인 후 복사

------login.html--------- -------

<html>
<head>
	<meta http-equiv="Content-Type" c/html; charset=utf-8" />
	<title>Login</title>
</head>
<body>
	<h1>用户登录</h1>
	<form method="POST" action="login.php">
	用 户 名:<input type="text" name="username" maxlength="30" size="30"></br></br>
	用户密码:<input type="password" name="password" maxlength="30" size="30"></br></br>
	<input type="submit" value="登录">
	</form>
</body>
</html>
로그인 후 복사

------------login.php---- ----------------------

<html>
<head>
	<meta http-equiv="Content-Type" c/html; charset=utf-8" />
	<title>Login</title>
	<?php 
		$c //连接并选择数据库服务器 
		mysql_query("set names utf8");
		mysql_select_db("cookie",$connection); 		
	?>
</head>
	<body>
		<?php
		
			$username = $_POST[&#39;username&#39;];
			$password = $_POST[&#39;password&#39;];
			
			if(!$password || !$username)
			{
				echo "用户名或密码不能为空,请重新输入!";
				exit;
			}
			@ $db = new mysqli(&#39;localhost&#39;,&#39;root&#39;,&#39;cookie&#39;,&#39;cookie&#39;);
			
			if(mysqli_connect_errno())
			{
				echo "数据库链接失败,请重试!";
				exit;
			}
			$query = "select * from userinfo where username = &#39;$username&#39; && passwd = &#39;$password&#39;";
			$result = $db->query($query);
			
			$num_results = $result->num_rows;
			
			if($num_results >0)
			{
				//echo "登录成功!";
                                <strong>include</strong> "userinfo.php";				
			}
			else
			{
				echo "用户名或密码错误,请确认!";
			}
			$db->close();
			?>
	</body>
</html>
로그인 후 복사

---- - -----------userinfo.php--------- - ----------

 <head>
	<meta http-equiv="Content-Type" c/html; charset=utf-8" />
	<title>Login</title>
</head>
<?php 
$c //连接并选择数据库服务器 
mysql_select_db("cookie",$connection); 
$query="select u.userid,u.userno,u.username,g.`gender`,p.`province`,c.`city`,d.`department`,po.`positions`,u.remark from userinfo as u 
<strong>left join</strong> gender as g on u.genderid = g.genderid <strong>left join</strong> province as p on u.provinceid = p.provinceid 
<strong>left join</strong> city as c on u.cityid = c.cityid <strong>left join</strong> department as d on u.departmentid = d.departmentid 
<strong>left join</strong> positions as po on u.positionid = po.positionid"; 
$result=mysql_query($query,$connection); 
?>
<table border="1" width="100%">
	<tr>
		<th>用户ID</th>
		<th>工号</th>
		<th>真实姓名</th>
		<th>性别</th>
		<th>省份</th>
		<th>城市</th>
		<th>部门</th>
		<th>职位</th>
		<th>备注</th>
		<th>操作</th>		
	</tr>
<?
while($row=mysql_fetch_array($result)) 
{ 
?>
<tr>
<td> <? echo $row[userid]."<br>"; ?></td> 
<td> <? echo $row[userno]."<br>";  ?></td> 
<td> <? echo $row[username]."<br>"; ?></td> 
<td> <? echo $row[gender]."<br>"; ?></td> 
<td> <? echo $row[province]."<br>"; ?></td> 
<td> <? echo $row[city]."<br>"; ?></td> 
<td> <? echo $row[department]."<br>"; ?></td> 
<td> <? echo $row[positions]."<br>"; ?></td> 
<td> <? echo $row[remark]."<br>"; ?></td> 
<td>编辑</td> 
<?
} 
?> 
로그인 후 복사

위 내용은 PHP 예제-등록 및 로그인에 대한 내용을 소개하고 있으며, PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿