Home > Topics > php mysql > body text

php implements login function

**
Release: 2021-10-13 09:21:11
Original
433 people have browsed it

Php简介:

引用:PHP即“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法学习了C语言,吸纳Java和Perl多个语言的特色发展出自己的特色语法,并根据它们的长项持续改进提升自己,例如java的面向对象编程,该语言当初创建的主要目标是让开发人员快速编写出优质的web网站。 PHP同时支持面向对象和面向过程的开发,使用上非常灵活。

经过二十多年的发展,随着php-cli相关组件的快速发展和完善,PHP已经可以应用在 TCP/UDP服务、高性能Web、WebSocket服务、物联网、实时通讯、游戏、微服务等非 Web 领域的系统研发。

我们开发php网站需要配置apache、mysql,利用集成环境开发网站,例如小皮面板、xampp等集成环境,现在我们利用PHP来做一个登录功能

前端页面:login.php

?>

 


 

Backend code: public/login.php

include_once 'server.php';

$user=$_GET['username'];

$pwd=$_GET['password'] ;

$sql="select * from user where user=$user and password=$pwd";

$result=$conn->query($sql);

if($result->num_rows>0){

$row=$result->fetch_assoc();//Get an array from the result set

echo json_encode( $row);//Convert to json format

session_start();

$_SESSION['name']=$user;

echo "";

}

else{

echo "";

}

$ result->free_result();

$conn->close();

?>

This code will take out the data if the login is successful. Failure will result in an incorrect account and password

Sever.php:

$servername="localhost";

$username='root ';

$password='123456';

$dbname='shop_center';

$conn=new mysqli($servername,$username,$password,$ dbname);

mysqli_set_charset($conn,'utf8');

if($conn->connect_error){

die(" Connection failed: ".$conn->connect_error);

}

//echo "Connection successful";

?>

This The code segment is the database connection code

Database creation statement

/*

Navicat MySQL Data Transfer

Source Server : stu1

Source Server Version : 50505

Source Host : localhost:3306

Source Database : shop_center

Target Server Type : MYSQL

Target Server Version : 50505

File Encoding : 65001

Date: 2021-04-29 18:57:52

*/

SET FOREIGN_KEY_CHECKS=0;

------------------ -----------

-- Table structure for `dingdan`

------------------ -----------

DROP TABLE IF EXISTS `dingdan`;

CREATE TABLE `dingdan` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`shopname` varchar(50) DEFAULT NULL,

`price` decimal(8,2) DEFAULT NULL,

`jieshao` varchar(50 ) DEFAULT NULL,

`img` int(11) DEFAULT NULL,

`count` int(11) DEFAULT NULL,

`sum` int(11) DEFAULT NULL,

`address` varchar(50) DEFAULT NULL,

`name` varchar(25) DEFAULT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

------------------------ -------

-- Records of dingdan

------------------------ ----

INSERT INTO `dingdan` VALUES ('4', 'Facial cleanser', '50.00', 'Very easy to use facial cleanser', '1', '1', null, null , '123');

-----------------------------------

-- Table structure for `gouwuche`

-- ----------------------------

DROP TABLE IF EXISTS `gouwuche`;

CREATE TABLE `gouwuche` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`shopname` varchar(25) DEFAULT NULL,

`price` decimal(8,2) DEFAULT NULL,

`jieshao` varchar(50) DEFAULT NULL,

`img` int(2) DEFAULT NULL,

`count` int(10) DEFAULT NULL,

`name` varchar(20) DEFAULT NULL,

`address` varchar( 50) DEFAULT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;

-- ----------------------------

-- Records of gouwuche

-- --- -----------------------

INSERT INTO `gouwuche` VALUES ('13', 'Facial Cleanser', '50.00' , 'A very useful facial cleanser', '1', '10', '123', null);

INSERT INTO `gouwuche` VALUES ('14', 'Skin care lotion', '60.00' , 'Soft skin, shiny and moisturized', '2', '3', '123', null);

INSERT INTO `gouwuche` VALUES ('15', 'Huawei mobile phone', '5000.00' , 'High quality, curved screen, fast refresh, no lag', '7', '2', '123', null);

-- ----- -----------------------

-- Table structure for `shop`

-- ----- -----------------------

DROP TABLE IF EXISTS `shop`;

CREATE TABLE `shop` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`shopname` varchar(25) DEFAULT NULL,

`price` decimal(8,2) DEFAULT NULL,

`jieshao` varchar(50) DEFAULT NULL,

`img` int(2) DEFAULT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;

----------------------- ---

-- Records of shop

--------------------------------

INSERT INTO `shop` VALUES ('1', 'Facial cleanser', '50.00', 'Very easy to use facial cleanser', '1');

INSERT INTO `shop ` VALUES ('2', 'skin lotion', '60.00', 'soft skin, radiant and moisturizing', '2');

INSERT INTO `shop` VALUES ('3', 'headphones' , '50.00', 'Bluetooth headset, long standby', '3');

INSERT INTO `shop` VALUES ('4', 'High-quality headset', '100.00', 'Clear sound quality, High-quality lossless sound quality', '4');

INSERT INTO `shop` VALUES ('5', 'Slippers', '20.00', 'Durable and very comfortable', '5');

INSERT INTO `shop` VALUES ('6', 'Mobile phone', '980.00', 'Fast refresh, two minutes of charging, two hours of talk time', '6');

INSERT INTO `shop` VALUES ('7', 'Huawei mobile phone', '5000.00', 'High quality, curved screen, fast refresh, no lag', '7');

INSERT INTO `shop` VALUES ('8', 'Conditioner', '50.00', 'Moisturize the scalp, protect the hair, and make the bald head look long and flowing', '8');

INSERT INTO `shop` VALUES (' 9', 'iPhone', '5000.00', 'High quality, Apple brings you a different experience', '9');

INSERT INTO `shop` VALUES ('10', 'Luggage Box', '280.00', 'Silent wheel, strong load-bearing capacity, wear-resistant', '10');

INSERT INTO `shop` VALUES ('11', 'Toothpaste', '18.00', ' Contains tea polyphenols to whiten teeth', '11');

INSERT INTO `shop` VALUES ('12', 'Sensodyne Toothpaste', '28.00', 'Prevent tooth sensitivity and whiten teeth, Prevent gum bleeding', '12');

---------------------------- --

-- Table structure for `user`

---------------------------- --

DROP TABLE IF EXISTS `user`;

CREATE TABLE `user` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`user` varchar(25) DEFAULT NULL,

`password` varchar(25) DEFAULT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

-------------------------------

-- Records of user

-----------------------------

INSERT INTO `user` VALUES ('1', '123', '123');

INSERT INTO `user` VALUES ('2', '', '');

INSERT INTO `user` VALUES ('3', '12121', '212');

The above is the detailed content of php implements login function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
1
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template