search

求一个用php做的注册和登录页面能提交到mysql的,端口是3307,数据库名是bbs,
表名是user-info,注册的是register.php 登录的是login.php
求代码,用来参考学习


回复讨论(解决方案)

这种代码网上很多吧,随便一搜一大把。

其实php的登录注册,说白了就是php执行select跟insert SQL语句,然后做些相应的跳转。

我想要的是代码,能给我提供学习

骚年,百度/google一下就有了,何必在这等别人给你写呢

随便下载个开源的你就可以看到了。

 不是这缺就是哪个对方不对的,改起来麻烦,我对php还不是很熟悉,我是做java  我们部门要求掌握php的一些基础知识,所以喽

<?phpif(!in_array($_POST['type'],array('login','reg'))){	echo -1;	exit();}if($_POST['type']=='login'){	$username=addslashes($_POST['username']);	$pwd=$_POST['pwd'];	$sql="SELECT * FROM test WHERE name='$username'";//test改为user-info	$db=new DB();	if($user_exists=$db->execute_dql($sql)){		if(md5($pwd)==$user_exists[0]['pwd']){			session_start();			$_SESSION['username']=$user_exists[0]['name'];			echo 1;			exit();		}	}else{		echo -1;		exit();	}}elseif($_POST['type']=='reg'){	$username=addslashes($_POST['username']);	$pwd=md5($_POST['pwd']);	$sql_exists="SELECT * FROM test WHERE name='$username'";//test改为user-info	$db=new DB();	if($db->execute_dql($sql_exists)){//已存在该用户		echo -2;		exit();	}	$sql="INSERT INTO test(name,pwd) VALUES('$username','$pwd')";//test改为user-info	if($code=$db->execute_dml($sql)){		session_start();		$_SESSION['username']=stripslashes($username);		echo 1;		exit();	}else{		echo -1;		exit();	}}class DB{	private $conn;	private $host="localhost";//localhost:3307	private $user="root";	private $password="123456";	private $db="test";//bbs	private $res;	function __construct(){		$this->conn=mysql_connect($this->host,$this->user,$this->password);		if(!$this->conn){			die("连接数据库失败".mysql_error());		}		mysql_select_db($this->db,$this->conn);		mysql_query("SET NAMES utf8");	}	function execute_dql($sql){		$this->res=mysql_query($sql,$this->conn) or die(mysql_error());		$r=array();		while($row=mysql_fetch_assoc($this->res)){			$r[]=$row;		}		return $r;	}	function execute_dml($sql){		$b=mysql_query($sql,$this->conn) or die(mysql_error());		if(!$b){			return 0;//失败		}else{			if(mysql_affected_rows($this->conn)>0){				return 1;//成功			}else{				return 2;//没有影响到行数			}		}	}	function __destruct(){		if(!empty($this->res)){			mysql_free_result($this->res);		}		mysql_close($this->conn);	}}?>


exe.php
<?phpif(!in_array($_POST['type'],array('login','reg'))){	echo -1;	exit();}if($_POST['type']=='login'){	$username=addslashes($_POST['username']);	$pwd=$_POST['pwd'];	$sql="SELECT * FROM test WHERE name='$username'";//test改为user-info	$db=new DB();	if($user_exists=$db->execute_dql($sql)){		if(md5($pwd)==$user_exists[0]['pwd']){			session_start();			$_SESSION['username']=$user_exists[0]['name'];			echo 1;			exit();		}	}else{		echo -1;		exit();	}}elseif($_POST['type']=='reg'){	$username=addslashes($_POST['username']);	$pwd=md5($_POST['pwd']);	$sql_exists="SELECT * FROM test WHERE name='$username'";//test改为user-info	$db=new DB();	if($db->execute_dql($sql_exists)){//已存在该用户		echo -2;		exit();	}	$sql="INSERT INTO test(name,pwd) VALUES('$username','$pwd')";//test改为user-info	if($code=$db->execute_dml($sql)){		session_start();		$_SESSION['username']=stripslashes($username);		echo 1;		exit();	}else{		echo -1;		exit();	}}class DB{	private $conn;	private $host="localhost";//localhost:3307	private $user="root";	private $password="123456";	private $db="test";//bbs	private $res;	function __construct(){		$this->conn=mysql_connect($this->host,$this->user,$this->password);		if(!$this->conn){			die("连接数据库失败".mysql_error());		}		mysql_select_db($this->db,$this->conn);		mysql_query("SET NAMES utf8");	}	function execute_dql($sql){		$this->res=mysql_query($sql,$this->conn) or die(mysql_error());		$r=array();		while($row=mysql_fetch_assoc($this->res)){			$r[]=$row;		}		return $r;	}	function execute_dml($sql){		$b=mysql_query($sql,$this->conn) or die(mysql_error());		if(!$b){			return 0;//失败		}else{			if(mysql_affected_rows($this->conn)>0){				return 1;//成功			}else{				return 2;//没有影响到行数			}		}	}	function __destruct(){		if(!empty($this->res)){			mysql_free_result($this->res);		}		mysql_close($this->conn);	}}?>

上面发错了,前台页面,用了jquery

<html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"><script language="javascript" type="text/javascript" src="jquery.min.js"></script><script type="text/javascript">$(function(){	$(':button[name=login]').click(function(){		var username=$('#l_username').val();		var pwd=$('#l_pwd').val();		if($.trim(username)=='' || $.trim(pwd)==''){			alert('用户名或密码不能为空');			return false;		}		$.ajax({			type:'post',			url:'exe.php',			data:{				username:username,				pwd:pwd,				type:'login'			},			success:function(res){				if(res==1){					window.location.reload();				}else{					alert('用户名或密码错误');				}			}		});	})	$(':button[name=reg]').click(function(){		var username=$('#r_username').val();		var pwd=$('#r_pwd').val();		var pwd1=$('#r_pwd1').val();		if($.trim(username)=='' || $.trim(pwd)=='' || $.trim(pwd1)==''){			alert('用户名或密码不能为空');			return false;		}		if($.trim(pwd)!=$.trim(pwd1)){			alert('两次输入不匹配');			return false;		}		$.ajax({			type:'post',			url:'exe.php',			data:{				username:username,				pwd:pwd,				type:'reg'			},			success:function(res){				if(res==1){					alert('注册成功');					window.location.reload();				}else if(res==-2){					alert('用户名已存在');				}else{					alert('注册失败');				}			}		});	})})</script></head><body><?phpsession_start();if(isset($_SESSION['username']) && !empty($_SESSION['username'])){	echo $_SESSION['username'].'   欢迎回来';}else{?><div>	<h3 id="登录">登录</h3>	用户名:<input type="text" id="l_username"><br/>	密 码:<input type="password" id="l_pwd"><br/>	<input type="button" name="login" value="登录" ></div><hr><div>	<h3 id="注册">注册</h3>	用户名:<input type="text" id="r_username"><br/>	密 码:<input type="password" id="r_pwd"><br/>	确 认:<input type="password" id="r_pwd1"><br/>	<input type="button" name="reg" value="注册"></div><?php }?></body></html>

楼主你赢啦。

网上有好多啊,搜一搜。

搜搜更健康。

多看看就有的,加油楼主

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
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Introduction to the Instagram APIIntroduction to the Instagram APIMar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

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
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

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!