如何在我的网站的数据库中手动创建用户和密码

时间:2018-11-09 00:12:56

标签: php session mysqli

我正在关注登录系统教程,并且发现了一些小问题。下一步是在MySQL数据库中创建一个手动用户,以便能够登录。我只需要一个用户。本教程未显示其注册部分。

这是login.php代码:

<?php
include("config.php");
session_start();

if($_SERVER["REQUEST_METHOD"] == "POST") {
  // username and password sent from form 

  $myusername = mysqli_real_escape_string($db,$_POST['username']);
  $mypassword = mysqli_real_escape_string($db,$_POST['password']); 

  $sql = "SELECT id FROM admin WHERE username = '$myusername' and passcode = '$mypassword'";
  $result = mysqli_query($db,$sql);
  $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  $active = $row['active'];

  $count = mysqli_num_rows($result);

  // If result matched $myusername and $mypassword, table row must be 1 row

  if($count == 1) {
     session_register("myusername");
     $_SESSION['login_user'] = $myusername;

     header("location: welcome.php");
  }else {
     $error = "Your Login Name or Password is invalid";
    }
 }
?>

1 个答案:

答案 0 :(得分:0)

执行此SQL查询:

def __init__(self, project_id): self.project_id = project_id

INSERT INTO admin ( username, passcode) VALUES ( 'testuser', 'testpassword' )testuser更改为所需的用户名和密码。