search
HomeTopicsphp mysqlHow to connect php to mysql to implement a simple registration login page

php mysql tutorial column introduces the implementation of a simple registration login page.

How to connect php to mysql to implement a simple registration login page

Recommended: php myql tutorial

Login page index.html
How to connect php to mysql to implement a simple registration login page
Registration page register.html
How to connect php to mysql to implement a simple registration login page

After installing the Mysql database, use the MySQL database management page phpmyadmin creates database and form

Browser input: domain name/phpmyadmin, no domain name input: ip/phpmyadmin or 127.0.0.1/phpmyadmin (127.0.0.1 is the local address)
How to connect php to mysql to implement a simple registration login page
Create a form in the database How to connect php to mysql to implement a simple registration login page

The code is as follows:

index.html

nbsp;html>
    <meta>
    <title>登录</title>
    <p>
        <b>登录</b>
        </p>
            

用户名:

            

密码:

            

 

        
        新用户注册     

login.php

<meta><?php     $conn = mysqli_connect(&#39;localhost&#39;,&#39;root&#39;,&#39;password&#39;,&#39;db_name&#39;) or die(&#39;数据库连接失败&#39;);
    $conn->query("SET NAMES 'UTF8'");
 
    $user = $_POST['user'];
    $pass = $_POST['pass'];
    $sql="SELECT * FROM users where user='{$user}' and pass='{$pass}'"; 
 
    $result=$conn->query($sql);
    $row = mysqli_num_rows($result);
	//若表中存在输入的用户名和密码,row=1;若表中用户名不存在或密码错误,则row=0
 
    if($row == 1){
        echo $row['user']."登陆成功!";
    }
    else{
        echo"登录失败,请重新登录!";
    }	?>	

register.html

nbsp;html>
    <meta>
    <title>注册</title>
    <p>
        <b>注册</b>
        </p>
            

用户名:

            

密码:

            

联系:

            

                              

        
        已注册     

register. php

<?php     header ( "Content-type:text/html;charset=utf-8" );
    $conn = mysqli_connect(&#39;localhost&#39;,&#39;root&#39;,&#39;password&#39;,&#39;db_name&#39;) or die(&#39;数据库连接失败&#39;);
    $conn->set_charset('utf8');

    $user = $_POST['user'];
    $pass = $_POST['pass'];
    $connect = $_POST['connect'];
 	
    $sql = "INSERT INTO users(id,user,pass,connect) 
    			VALUES (null,'{$user}' ,'{$pass}','{$connect}')";
    mysqli_query($conn,$sql) or die(mysqli_error($conn));
    echo("注册成功!!!<br><a>点击登录</a>")     ?>

————————————————————————————————————

Supplement: (pits that have been stepped on)

1. How to connect to the database with PHP7: using mysqli or PDO
When using mysqli_connect(), use localhost as the address It's not an IP, otherwise you won't be able to connect to the server.
Reference: https://blog.csdn.net/zwliang98/article/details/82997349

##2. php outputs the error message of executing the sql statement:

mysqli_query($conn,$sql) or die(mysqli_error( $conn ));

3. bug
bug 1:
Incorrect integer value: '' for column 'id' at row 1
For versions above php5, if the value is empty, NULL should be written

#错误
$sql = "INSERT INTO users(id,user,pass,connect) VALUES ('','{$user}' ,'{$pass}','{$connect}')";#改为
$sql = "INSERT INTO users(id,user,pass,connect) VALUES (null,'{$user}' ,'{$pass}','{$connect}')";

bug 2:
Incorrect string value: ' \xE7\x94\xB7' for column 'sex' at row 1
Link: MySQL insert Chinese error problem method

The above is the detailed content of How to connect php to mysql to implement a simple registration login page. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete

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)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

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.