PHP develops a ...LOGIN

PHP develops a simple book lending system to create database and user table

First we create a database about books, named book.

<?php
// 创建连接
$conn = new mysqli("localhost", "uesename", "password");
// 检测连接
if ($conn->connect_error) 
{    
    die("连接失败: " . $conn->connect_error);} 
    // 创建数据库
    $sql = "CREATE DATABASE book";
        if ($conn->query($sql) === TRUE) 
        {    
        echo "数据库创建成功";
        } else {    
        echo "Error creating database: " . $conn->error;
        }
    $conn->close();
?>

Create a table in the database that needs to be used for user registration and login, named user

Set the following fields:

id: It is unique, type is int, and select the primary key.

name: User name, type is varchar, length is 100.

password: Password, type is varchar, length is 100.

email: Email, type is varchar, length is 100.

tel: Telephone, type is varchar, length is 100.

address: Address, type is varchar, length is 200.

<?php
$SQL = " CREATE TABLE IF NOT EXISTS `user` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  `password` varchar(100) DEFAULT NULL,
  `email` varchar(100) DEFAULT NULL,
  `tel` varchar(100) DEFAULT NULL,
  `address` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ";
?>

Of course you can also create it directly in phpMyAdmin.

Write the created database table into the config.php file so that we can call the database table on different pages in the future.

<?php

ob_start();
session_start(); //开启缓存
header("Content-type:text/html;charset=utf-8");

$link = mysqli_connect('localhost','root','root','book');
mysqli_set_charset($link, "utf8");
if (!$link) {
  die("连接失败:".mysqli_connect_error());
}
?>


Next Section
<?php // 创建连接 $conn = new mysqli("localhost", "uesename", "password"); // 检测连接 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error);} // 创建数据库 $sql = "CREATE DATABASE book"; if ($conn->query($sql) === TRUE) { echo "数据库创建成功"; } else { echo "Error creating database: " . $conn->error; } $conn->close(); ?>
submitReset Code
ChapterCourseware