PHP login code will not proceed past $result = mysqli_query($conn, $sql);

  Kiến thức lập trình

im trying to create a login page for my website and I am trying to just get the function to work but the code wont make it any further than $result = mysqli_query($conn, $sql); and i dont understand why.
Login.php


<?php
    include('connection.php');
    if (isset($_POST['submit'])) {
        $username = $_POST['user'];
        $password = $_POST['pass'];
       
        $sql = "select * from login where username = '$username' and password = '$password'";  
        ?> <h1><a href="index.php">code made it this far</a></h1> <?php 
        $result = mysqli_query($conn, $sql);  //this stops the code from proceeding
       
     
        $row = mysqli_fetch_array($result, MYSQLI_ASSOC);  
        $count = mysqli_num_rows($result);
        
        if($count == 1){  
            header("Location:welcome.html");
        }
        else{  
            die("connection failed");
        }
        
    }
    ?>

Index.php

<?php include "connection.php"?>
<!DOCTYPE html>
<html>

<div id="form">
            <h1>Login Form</h1>
            <form name="form" action="login.php" onsubmit="return isvalid()" method="POST">
                <label>Username: </label>
                <input type="text" id="user" name="user"></br></br>
                <label>Password: </label>
                <input type="password" id="pass" name="pass"></br></br>
                <input type="submit" id="btn" value="Login" name = "submit"/>
            </form>
        </div>
</form>
</html>

Connection.php

<?php
$server_name="localhost";   
$username="root";
$password="root";
$db_name="database1";
$connection=new mysqli($server_name,$username,$password,$db_name);
if($conn->connect_error){
    die("connection failure".$conn->connect_error);

}
echo"you are connected";

?>
<!DOCTYPE html>

<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
       
    </head>
    <body>
    <h1>login successful</h1>

    </body>
</html>

I know the code is flawed im currently just trying to get it to work before i start adding extra measures

the code wont proceed pass the line and I understand why, I have copied multiple tutorials and none of them have worked and im not sure why

New contributor

Ryan Llewellyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT