Home Backend Development PHP Tutorial php example-registration & login

php example-registration & login

Jul 29, 2016 am 09:15 AM
gt lt quot select

------------------------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>
Copy after login

------------------------------------------------ -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>
Copy after login

--------------------------------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); 
			}
?>
Copy after login

-----------------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>
Copy after login

------------------------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>
Copy after login

----------------------------- --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> 
<?
} 
?> 
Copy after login

The above introduces the PHP example-registration & login, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
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

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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Asynchronous processing method of Select Channels Go concurrent programming using golang Asynchronous processing method of Select Channels Go concurrent programming using golang Sep 28, 2023 pm 05:27 PM

Asynchronous processing method of SelectChannelsGo concurrent programming using golang Introduction: Concurrent programming is an important area in modern software development, which can effectively improve the performance and responsiveness of applications. In the Go language, concurrent programming can be implemented simply and efficiently using Channels and Select statements. This article will introduce how to use golang for asynchronous processing methods of SelectChannelsGo concurrent programming, and provide specific

How to hide the select element in jquery How to hide the select element in jquery Aug 15, 2023 pm 01:56 PM

How to hide the select element in jquery: 1. hide() method, introduce the jQuery library into the HTML page, you can use different selectors to hide the select element, the ID selector replaces the selectId with the ID of the select element you actually use; 2. css() method, use the ID selector to select the select element that needs to be hidden, use the css() method to set the display attribute to none, and replace selectId with the ID of the select element.

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

How to implement change event binding of select elements in jQuery How to implement change event binding of select elements in jQuery Feb 23, 2024 pm 01:12 PM

jQuery is a popular JavaScript library that can be used to simplify DOM manipulation, event handling, animation effects, etc. In web development, we often encounter situations where we need to change event binding on select elements. This article will introduce how to use jQuery to bind select element change events, and provide specific code examples. First, we need to create a dropdown menu with options using labels:

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

What is the reason why Linux uses select? What is the reason why Linux uses select? May 19, 2023 pm 03:07 PM

Because select allows developers to wait for multiple file buffers at the same time, it can reduce IO waiting time and improve the IO efficiency of the process. The select() function is an IO multiplexing function that allows the program to monitor multiple file descriptors and wait for one or more of the monitored file descriptors to become "ready"; the so-called "ready" state is Refers to: the file descriptor is no longer blocked and can be used for certain types of IO operations, including readable, writable, and exceptions. select is a computer function located in the header file #include. This function is used to monitor file descriptor changes—reading, writing, or exceptions. 1. Introduction to the select function. The select function is an IO multiplexing function.

See all articles