PHP development user login module to create database and table

Here we use phpMyAdmin to create MySql database and tables.

The CREATE DATABASE statement is used to create a database in MySQL.

We first create a test database:

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

The CREATE TABLE statement is used to create a MySQL table.

Set the following fields:

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

uesrname: Username, type is varchar, length is 30.

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

Then create a login table in the test database:

<?php
// 创建连接
$conn = new mysqli("localhost", "uesename", "password","test");
// 检测连接
if ($conn->connect_error) 
{    
die("连接失败: " . $conn->connect_error);
} 
// 使用 sql 创建数据表
$sql = "CREATE TABLE login (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL,)ENGINE=InnoDB DEFAULT CHARSET=utf8 ";
if ($conn->query($sql) === TRUE) 
{    
echo "Table MyGuests created successfully";
} else {    
echo "创建数据表错误: " . $conn->error;
}
$conn->close(); 
?>

Add a username and password for testing

<?php
$SQL = "INSERT INTO login ('id','username','password') VALUES ('7', 'tom', '12345');"
?>

You can also directly create the database and table through phpMyAdmin

ku.png

Write the database name in the red box on the left (ours is called test), and then click the red box on the right to create it directly.

biao.png

Click the red box on the left to jump to the new database table page on the right, fill in the table name in the data table name (ours is the login table), and then click Execute That’s it.

Finally complete the data filling in the table, similar to the picture below:

bi.png

Click on the lower right corner to save, and you can create a simple database table.

b2.png

#Click Insert in the title bar to enter data, and then click Browse to query the entered data.

b3.png

We entered a username as tom; password is 12345.

Continuing Learning
||
<?php // 创建连接 $conn = new mysqli("localhost", "uesename", "password","test"); // 检测连接 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } // 使用 sql 创建数据表 $sql = "CREATE TABLE login ( id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY, username VARCHAR(30) NOT NULL, password VARCHAR(30) NOT NULL,)ENGINE=InnoDB DEFAULT CHARSET=utf8 "; if ($conn->query($sql) === TRUE) { echo "Table MyGuests created successfully"; } else { echo "创建数据表错误: " . $conn->error; } $conn->close(); ?>
submitReset Code