duanhan7001 2015-12-05 15:48
浏览 28
已采纳

PHP / MYSQLI登录表单是否接受任何条目? [重复]

This is my first login form using PHP?MYSQLI. I'm doing a tutorial on simplest.com/siteezy.com, and am having trouble with the login process. The main issue being that the form will accept any input entered (even blank fields), and bring the person to the logged in page (account.php), whether they have registered on the site or not. The registration side of things seems to work fine. I've watched the tutorials several times, and copied the code to the letter..I'm wondering if I'm missing something here? Can't seem to find the answer here in other questions. Thanks!

<?php require 'connect.php'; ?>

<?php

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

             $emailaddress = $_POST['EmailAddress'];
             $password = $_POST['Password'];

             $result = $con->query("SELECT * FROM users WHERE EmailAddress='$emailaddress' AND Password='$password'");

             $row = $result->fetch_array(MSQLI_BOTH);

             session_start();

             $_SESSION["UserID"] = $row['UserID'];

             header('Location: account.php');

}
?>




<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="style/style.css">


</head>
<body>

<div class="container">



<!-- LOGIN FORM -->
<h3>Login here</h3>
<form action="" method="post" name="loginform" id="loginform">
<div class="form-group"> 
<div>Email Address:</div>
<input id="emailaddress" type="email" required="required" name="emailaddress" maxlength="88" class="form-control">
</div>
<div class="form-group">  
<div>Password:</div>
<input id="password" type="password" name="password" class="form-control">
</div>

<input name="login" type="submit" class="button" value="login">

</form>

</div>
</div>
  • 写回答

1条回答 默认 最新

  • donglvchu9143 2015-12-05 15:54
    关注

    You should check if the form elements are set. For example:

    if(isset($_POST['emailaddress']) && isset($_POST['password']))
    

    Then check that the number of rows are greater than 1:

    if($result->num_rows > 1)
    

    And if so only then you should redirect to the second page. else do nothing.

    EDIT :

    <?php require 'connect.php'; ?>
    
    <?php
    
    if(isset($_POST['emailaddress']) && isset($_POST['password'])){
    
                 $emailaddress = $_POST['emailaddress'];
                 $password = $_POST['password'];
    
                 $result = $con->query("SELECT * FROM users WHERE EmailAddress='$emailaddress' AND Password='$password'");
    
                 if($result->num_rows > 0) {
    
                     session_start();
    
                     $_SESSION["UserID"] = $row['UserID'];
    
                     header('Location: account.php');
                 }
    
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错