简体   繁体   中英

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

<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. Besides that, the <table> is also missing :)

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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