简体   繁体   English

创建登录页面,但单击按钮不会显示任何数据或错误消息

[英]creating a login page but button click doesn't show any data or error messages

When i click on the submit button it doesn't show any error and does not respond with any message.after a click it only reload itself and doesn't show any data. 当我单击提交按钮时,它不显示任何错误,也不响应任何消息。单击后,它仅重新加载自身,不显示任何数据。 please reply me with the error. 请以错误答复我。

I found I missed the tag. 我发现我错过了标签。 It was a silly mistake. 这是一个愚蠢的错误。

<?php
    $server="localhost";
    $username="root";
    $password="admin007#";
    $dbname="demo";

    $con=new mysqli($server,$username,$password,$dbname); 
    if(!$con)
     {
      die('error connecting to the database');
     }


  if(isset($_POST['login'])){
    $a=mysqli_real_escape_string($con, $_POST['user']);
    $b=mysqli_real_escape_string($con, $_POST['pass']);
    $sql="SELECT * FROM login WHERE username='$a' AND password='$b'";
    $result=mysqli_query($con, $sql);
    $check=mysqli_num_rows($result);
    if($check>0){
       echo "you are logged in";    
    }
    else
    {
      echo "Error";
    }
 }

?>

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Untitled Document</title>
   </head>
   <body>
      <tr>
         <td>Username:</td>
         <td><input type="text" name="user" value=""/></td>
      </tr>
      <br /><br />
      <tr>
         Password:
         <td><input type="password" name="pass" value=""/></td>
      </tr>
      <br />
      <tr align="center">
         <td colspan="2"><input type="submit" name="login" value="Log In"/></td>
      </tr>
   </body>
</html>

There is a <form> Tag missing 缺少<form>标记

<body>
  <form action="#" method="post">
    <tr>
      <td>Username:</td>
      <td>
        <input type="text" name="user" value="" />
      </td>
    </tr>
    <br />
    <br />
    <tr>
      Password:
      <td>
        <input type="password" name="pass" value="" />
      </td>
    </tr>
    <br />
    <tr align="center">
      <td colspan="2">
        <input type="submit" name="login" value="Log In" />
      </td>
    </tr>
  </form>
</body>

The <form method="post"> around the input fields is missing. 输入字段周围的<form method="post">丢失了。 Besides that, the <table> is also missing :) 除此之外, <table>也丢失了:)

Make the magic happen with something like: 通过以下方式使魔术发生:

<body>
<form method="post">
<table>
<tr>
<td>Username:</td>
<td><input type="text" name="user" value=""/></td>
</tr>
<tr>
Password:
<td><input type="password" name="pass" value=""/></td>
</tr>
<tr align="center"><td colspan="2"><input type="submit" name="login"  value="Log In"/></td></tr>
</table>
</form>
</body>

PS: No <br> Tags between <tr> Tags - thats semantic nonsense (use CSS instead) ... and modern day HTML developers will go full rage when you use <table> tags for layout purposes :) PS:在<tr>标记之间没有<br>标记-多数民众赞成在语义上的废话(改用CSS)...并且当您将<table>标记用于布局目的时,现代HTML开发人员会大吃一惊:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM