PHP implements a humble sign-in page

Source: Internet
Author: User

PHP implements a humble sign-in page

Today to water a no * * use of/Funny Face, code humble bloated consideration is not complete, you big guy light spray, still hope to enlighten.
First consider the need for at least four pages: register.html , register.php , login.html , login.php .
register.htmlIt's written like this:

<!DOCTYPE html>

register.phpIt's written like this:

<?php header("Content-type:text/html;charset=utf-8"); $conn=new mysqli('localhost','wy','000000','test'); if ($conn->connect_error){ die("服务器连接失败!"); } $name=$_POST["name"]; $password=$_POST["password"]; $sql="insert into new_info values('$name',$password)"; $res=$conn->query($sql); if(!$res){ echo "注册失败!"; }else{ if($conn->affected_rows>0){ echo "注册成功!"; }else{ echo "注册失败"; } } $conn->close();?>

login.htmlIt's written like this:

<!DOCTYPE html>

login.phpIt's written like this:

<?php header("Content-type:text/html;charset=utf-8"); $conn=new mysqli('localhost','wy','000000','test'); if ($conn->connect_error){ die("服务器连接失败!"); } $name=$_POST["name"]; $password=$_POST["password"]; $sql_name="select name from new_info where name='$name'"; $res_sql=$conn->query($sql_name); if($conn->affected_rows==0){ die("账号或密码有误"); }else{ $sql_pass="select password from new_info where name='$name'"; $res_pass=$conn->query($sql_pass); $row_pass=$res_pass->fetch_row(); if($row_pass[0]==$password){ echo "登录成功!"; }else{ echo "账号或密码有误"; } } $conn->close();?>

Then look at the effect:

Look at the database:

You can see that the data has been written to the database.
Then login to try it:

Try a different password:

PHP implements a humble sign-in page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.