如何使我的登录表单工作 [英] How Do I Make My Login Form Work

查看:105
本文介绍了如何使我的登录表单工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使我的用户登录系统功能正常但如果我输入的信息不在数据库中,它会自动将我带入仅供用户使用的文件中。我该如何解决?





register.php:



I am trying to make my user login system function properly but if i put in information that isn't in the database it automatically takes me into the file that is for users only . How can i fix it ?


register.php:

<?php

include('db.php');



if (isset($_POST['submit'])) {

    if ($_POST['password'] == $_POST['password2']) {

        $username = $_POST['username'];

        $password = $_POST['password'];

        $password2 = $_POST['password2'];

        $email = $_POST['email'];



      $sql = "INSERT into users VALUES(null, '$username', '$password', '$password2', '$email')";

        mysqli_query($conn, $sql);

    }

}

//Here we will check do we have all inputs filled

if(empty($username)){



echo("Please enter a username to sign up.");

} else {

}



if(empty($password)){



echo("Please enter a password to sign up.");

} else {

}



if(empty($password2)){



echo("Please enter confirm password to sign up.");

} else {

}



if(empty($email)){



echo("Please enter a email to sign up.");

} else {

}



//Here we will check if the passwords match

if($password2 != $password){

    echo("Your passwords don't match");

} else {



}



// user login code



 if(isset($_POST["user_login"]) && isset($_POST["password_login"]))  {

$user_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["user_login"]); //   filter everything but numbers and letters

$password_login_md5 = md5($password_login);

$password_login = preg_replace('#[^A-Za-z0-9]#i', '',     $_POST["password_login"]); // filter everything but numbers and letters

$sql = mysqli_query("SELECT id FROM users WHERE username= '$user_login' AND  password='$password_login_md5' LIMIT 1");



  //check for their user existance

  $userCount = mysqli_num_rows($sql); //count the number of rows returned

  if($userCount == 1) {

    while($row = mysqli_fetch_array($sql)){

        $id = $row["id"];

    }

    $_SESSION["user_login"] = $user_login;

    header("location: home.php");

    exit();

}



} else{

    echo'That information is incorrect, try again';

    exit();

}

?>
<html>
<head>
<title>InterFace</title>
<link rel="stylesheet" type="text/css" href="css.css" >
</head>
<body bgcolor="#E6E6FA">

<nav>
    <div id="logo">
    <h1 style="font-size: 30px">InterFace</h1>
    <div>

    <form action="account.php" method="POST">
    <h2 style="text-align: left"><b style="font-size: 25px">Log In</b></h2>
    <p align="left"><input type="text" name="user_login" size="35" id="Username" placeholder="User Name" /></p>
    <p align="left"><input type="password" name="password_login" size="35"  id="Password" placeholder="Password" /></p>
    <p align="left"><input type="submit" name="login" value="Login"></p>
    </form>
    </div>

    </div>
</nav>
<h3 style="text-align: right"><b style="font-size: 25px">Sign Up Below</b></h3>
<form name="registration" method="post" action="">
  <p align="right"><input type="text" name="username" size="35" id="Username" placeholder="User Name" /></p>
    <br></br>
  <p align="right"><input type="password" name="password" size="35"  id="Password" placeholder="Password" /></p>
    <br></br>
  <p align="right"><input type="password" name="password2" size="35"  id="Password2" placeholder="Confirm Password" /></p>
    <br></br>
  <p align="right"><input type="text" name="email" size="35"  id="Email" placeholder="E-mail" /></p>
  <p align="right"><input type="submit" name="submit" value="submit"></p>
  </form>

</body>
</html>

推荐答案

_POST['submit'])) {

if (
_POST['submit'])) { if (


_POST['password'] ==
_POST['password'] ==


_POST['password2']) {

_POST['password2']) {


这篇关于如何使我的登录表单工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆