So I was following [this](https://www.youtube.com/watch?v=e8TP2FERKls&t=914s) youtube guide on setting up a log in system with PHP, and I ran into some trouble when I got to the authentication part where the user's username and password are check against the database. Even when a correct username and password that are in the database are submitted, the if statement in login.php echos "Incorrect username or password!"

dbh.php <= this connects to the local databse

```
<?php
  $conn = mysqli_connect("localhost", "admin", "admin", "user_list");

  if(!$conn) {
    die("Connection failed");
  }
?>

```

sign\_up.php <= takes user account info and enters it into the database

```
<?php
  include 'dbh.php';

  $first = $_POST['first'];
  $last = $_POST['last'];
  $uid = $_POST['uid'];
  $pwd = $_POST['pwd'];

  $sql = "INSERT INTO user (first, last, uid, pwd)
          VALUES ('$first', '$last', '$uid', '$pwd')";
  $result = mysqli_query($conn, $sql);

  header("Location: login_page.html");
?>

```

login.php <= this takes user input and checks to see if a matching pair is in the databse

```
<?php
  include 'dbh.php';

  $uid = $_POST['uid'];
  $pwd = $_POST['pwd'];

  $sql = "SELECT * FROM user WHERE uid='$uid' AND pwd='$pwd'";
  $result = mysqli_query($conn, $sql);

  if (!$row = mysqli_fetch_assoc($result)) {
    echo "Your username or password is incorrect!";
  } else {
    echo "You are logged in!";
  }

?>

```

login\_page.html (not full page just login/signup forms)

```
<div class="content">
        <form action="login.php">
            <input type="text" name="uid" placeholder="Username"><br>
            <input type="password" name="pwd" placeholder="Password"><br>
            <button type="submit">LOG IN</button>
            <br><br><br>
        </form>
    <form action="signup.php" method="POST">
      <input type="text" name="first" placeholder="Firstname"><br>
      <input type="text" name="last" placeholder="Lastname"><br>
      <input type="text" name="uid" placeholder="Username"><br>
      <input type="password" name="pwd" placeholder="Password"><br>
      <button type="submit">SIGN UP</button>
    </form>
  </div>

```