求一个用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>
楼主你赢啦。
网上有好多啊,搜一搜。
搜搜更健康。
多看看就有的,加油楼主

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

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

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.