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.html
It's written like this:
<!DOCTYPE html>
register.php
It'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.html
It's written like this:
<!DOCTYPE html>
login.php
It'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