Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么';当使用不正确的登录时,错误消息是否有效?_Php_Html_Mysql_Login Script - Fatal编程技术网

Php 为什么';当使用不正确的登录时,错误消息是否有效?

Php 为什么';当使用不正确的登录时,错误消息是否有效?,php,html,mysql,login-script,Php,Html,Mysql,Login Script,这周我刚开始学习php。我一直在做一个简单的php登录表单。每当我运行index.html代码并输入登录详细信息时,submit按钮就会将我带到front.html,而不管详细信息是否正确。据我理解,这意味着这种联系没有发生。我看了所有的东西,其他的东西都有漏洞,也不起作用。请帮助我理解为什么这个代码不起作用,以及如何修复它。 下面是index.html代码 <?php session_start(); ?> <!DOCTYPE html> <html>

这周我刚开始学习php。我一直在做一个简单的php登录表单。每当我运行index.html代码并输入登录详细信息时,submit按钮就会将我带到front.html,而不管详细信息是否正确。据我理解,这意味着这种联系没有发生。我看了所有的东西,其他的东西都有漏洞,也不起作用。请帮助我理解为什么这个代码不起作用,以及如何修复它。 下面是index.html代码

 <?php 
session_start();
?>

<!DOCTYPE html>
<html>
   <head>
      <title>Login</title>
   </head>
   <body>
      <div id="main">
         <h1>Sign in</h1> 
         <div id="login"> 
         <fieldset>
            <form action="login.php" method="post"> 
               <ul> 

                  <li><label>Username</label> <input type="text" size="30" name="username" required></li>
                  <li><label>Password</label> <input type="password" size="30"     name="password" required></li>
                  <li><input type="submit" value="Sign in"></li>              
               </ul>
            </form>
         </fieldset>
      </div>
      </div>
   </body>
</html>

登录
登录
  • 用户名
  • 密码
这是login.php代码

 <?php
// establish MySQLi connection

$con = mysqli_connect("localhost","root","","proj4");
if (!$con)
{
die("Connection was not established: ". mysqli_connect_errno());
}
// checking the user
if(isset($_POST['login'])){
$user = mysqli_real_escape_string($con,$_POST['username']);
$password = mysqli_real_escape_string($con,$_POST['pass']);
$get_user = "SELECT * FROM user where username ='$user' AND password='$password'";
$run_user = mysqli_query($con, $get_user);
$check_user = mysqli_num_rows($run_user);
if($check_user>0){
$_SESSION['username']=$user;
echo "<script>window.open('front.html','_self')</script>";
}
else {
echo "<script>alert('username or password is not correct')</script>";
}
}
?>

这里有几个问题,其中之一是表单的密码元素
name=“password”
与查询中的值不匹配,即
$\u POST['pass']

将其更改为
$\u POST['password']

另一个是以下条件语句:

if(isset($_POST['login'])){
您没有名为“login”的元素,我认为您希望在提交按钮中使用它

  • 该条件语句中的任何内容都不会执行
因此,您需要将“提交”按钮更改为:

<input type="submit" value="Sign in" name="login">

旁注:错误报告只能在暂存阶段进行,而不能在生产阶段进行。

感谢它仍然不起作用,我知道哈希函数,我只是想让这部分先工作,它仍然可以hasnt@user3555512自从你上次看到我的答案后,我做了一些修改。重新加载,我发现了其他东西。关于提交按钮和条件语句的那个。@user355512 Btw,是您在“一”页中的全部代码;HTML表单和SQL?或者,它们是两个独立的文件吗?我怀疑这是一份档案,但我不得不问。据我所知,我的答案应该有效。确保表、列、类型、长度、现有数据等的所有内容都正确无误。这些都是有价值的建议。它仍然不起作用。在torch中,它显示我按submit后的登录代码。登录名和索引是不同的文件。我在想应该有某种错误。它甚至不能很好地完成任务!
<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code